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 CHANGED
@@ -1,12 +1,10 @@
1
1
  import json
2
2
  from shadowPaySDK.interface.erc20 import ERC20Token
3
3
  from shadowPaySDK.interface.erc721 import ERC721Token
4
- from shadowPaySDK.interface.sol import SolTokens
5
- from shadowPaySDK.interface.sol import SOL
4
+ from shadowPaySDK.interface.sol import SOL as sol
6
5
  from shadowPaySDK.types.EVMcheque import Cheque
7
6
  from shadowPaySDK.types.SOLcheque import SOLCheque
8
7
  from shadowPaySDK.const import __ERC20_ABI__, __SHADOWPAY_ABI__ERC20__,__ALLOW_CHAINS__, __SHADOWPAY_CONTRACT_ADDRESS__ERC20__
9
- from shadowPaySDK.api import __MAIN__URL__, __CREATE__CHEQUE__, get_my_cheques, create_cheque
10
8
 
11
9
 
12
10
  # from shadowPaySDK.utils import parse_tx as PARSE_TX
shadowPaySDK/const.py CHANGED
@@ -1,8 +1,9 @@
1
1
  import json
2
-
2
+ from solders.pubkey import Pubkey
3
3
  __ALLOW_CHAINS__ = [
4
4
  56, # BSC Mainnet
5
5
  97, # BSC Testnet
6
+ 10143,
6
7
  0x1,
7
8
  0x1f984,
8
9
  0x38,
@@ -11,6 +12,9 @@ __ALLOW_CHAINS__ = [
11
12
  0xa
12
13
  ]
13
14
 
15
+
16
+
17
+
14
18
  __VERSION__ = "0.1.2"
15
19
 
16
20
 
@@ -27,10 +31,61 @@ __ERC20_ABI__ = json.loads("""[
27
31
  ]""")
28
32
 
29
33
  __SHADOWPAY_CONTRACT_ADDRESS__ERC20__ = {
30
- 97: "0x17a82E53a3b3f2acA7ceae8CA6B6b3B8F14e4441"
34
+ 97: "0x5487C0DdCbD5465F26B446c6CAB88D8d6F7DF23b",
35
+ 10143: "0x1d856f2eA4738d1a89E27dbfc8950a4976Db41a5"
31
36
  }
32
37
 
33
38
  __SHADOWPAY_ABI__ERC20__= json.loads("""[
39
+ {
40
+ "inputs": [
41
+ {
42
+ "internalType": "address",
43
+ "name": "_trassary",
44
+ "type": "address"
45
+ }
46
+ ],
47
+ "stateMutability": "nonpayable",
48
+ "type": "constructor"
49
+ },
50
+ {
51
+ "anonymous": false,
52
+ "inputs": [
53
+ {
54
+ "indexed": false,
55
+ "internalType": "bytes32",
56
+ "name": "id",
57
+ "type": "bytes32"
58
+ }
59
+ ],
60
+ "name": "ChequeClaimed",
61
+ "type": "event"
62
+ },
63
+ {
64
+ "anonymous": false,
65
+ "inputs": [
66
+ {
67
+ "indexed": false,
68
+ "internalType": "bytes32",
69
+ "name": "id",
70
+ "type": "bytes32"
71
+ }
72
+ ],
73
+ "name": "ChequeCreated",
74
+ "type": "event"
75
+ },
76
+ {
77
+ "anonymous": false,
78
+ "inputs": [
79
+ {
80
+ "indexed": true,
81
+ "internalType": "bytes32",
82
+ "name": "id",
83
+ "type": "bytes32"
84
+ }
85
+ ],
86
+ "name": "redeem",
87
+ "type": "event"
88
+ },
34
89
  {
35
90
  "inputs": [
36
91
  {
@@ -71,16 +126,16 @@ __SHADOWPAY_ABI__ERC20__= json.loads("""[
71
126
  "type": "function"
72
127
  },
73
128
  {
74
- "inputs": [
129
+ "inputs": [],
130
+ "name": "FEE_DENOMINATOR",
131
+ "outputs": [
75
132
  {
76
- "internalType": "address",
77
- "name": "newOwner",
78
- "type": "address"
133
+ "internalType": "uint256",
134
+ "name": "",
135
+ "type": "uint256"
79
136
  }
80
137
  ],
81
- "name": "changeOwner",
82
- "outputs": [],
83
- "stateMutability": "nonpayable",
138
+ "stateMutability": "view",
84
139
  "type": "function"
85
140
  },
86
141
  {
@@ -141,43 +196,6 @@ __SHADOWPAY_ABI__ERC20__= json.loads("""[
141
196
  "stateMutability": "nonpayable",
142
197
  "type": "function"
143
198
  },
144
- {
145
- "inputs": [
146
- {
147
- "internalType": "address",
148
- "name": "_treaseryAddress",
149
- "type": "address"
150
- }
151
- ],
152
- "name": "setTreasery",
153
- "outputs": [],
154
- "stateMutability": "nonpayable",
155
- "type": "function"
156
- },
157
- {
158
- "inputs": [
159
- {
160
- "internalType": "address",
161
- "name": "_trassary",
162
- "type": "address"
163
- }
164
- ],
165
- "stateMutability": "nonpayable",
166
- "type": "constructor"
167
- },
168
- {
169
- "anonymous": false,
170
- "inputs": [
171
- {
172
- "indexed": false,
173
- "internalType": "bytes32",
174
- "name": "id",
175
- "type": "bytes32"
176
- }
177
- ],
178
- "name": "ChequeCreated",
179
- "type": "event"
180
- },
181
199
  {
182
200
  "inputs": [
183
201
  {
@@ -207,68 +225,15 @@ __SHADOWPAY_ABI__ERC20__= json.loads("""[
207
225
  "stateMutability": "payable",
208
226
  "type": "function"
209
227
  },
210
- {
211
- "anonymous": false,
212
- "inputs": [
213
- {
214
- "indexed": true,
215
- "internalType": "bytes32",
216
- "name": "id",
217
- "type": "bytes32"
218
- }
219
- ],
220
- "name": "redeem",
221
- "type": "event"
222
- },
223
228
  {
224
229
  "inputs": [
225
- {
226
- "internalType": "uint256",
227
- "name": "_minFee",
228
- "type": "uint256"
229
- },
230
- {
231
- "internalType": "uint256",
232
- "name": "_maxFees",
233
- "type": "uint256"
234
- },
235
- {
236
- "internalType": "uint256",
237
- "name": "_minEth",
238
- "type": "uint256"
239
- },
240
- {
241
- "internalType": "uint256",
242
- "name": "_baseFee",
243
- "type": "uint256"
244
- }
245
- ],
246
- "name": "setFees",
247
- "outputs": [],
248
- "stateMutability": "nonpayable",
249
- "type": "function"
250
- },
251
- {
252
- "inputs": [
253
- {
254
- "internalType": "uint256",
255
- "name": "amount",
256
- "type": "uint256"
257
- },
258
230
  {
259
231
  "internalType": "address",
260
- "name": "_to",
232
+ "name": "newOwner",
261
233
  "type": "address"
262
234
  }
263
235
  ],
264
- "name": "withdrawAmount",
265
- "outputs": [],
266
- "stateMutability": "nonpayable",
267
- "type": "function"
268
- },
269
- {
270
- "inputs": [],
271
- "name": "withdrawFees",
236
+ "name": "changeOwner",
272
237
  "outputs": [],
273
238
  "stateMutability": "nonpayable",
274
239
  "type": "function"
@@ -286,19 +251,6 @@ __SHADOWPAY_ABI__ERC20__= json.loads("""[
286
251
  "stateMutability": "view",
287
252
  "type": "function"
288
253
  },
289
- {
290
- "inputs": [],
291
- "name": "FEE_DENOMINATOR",
292
- "outputs": [
293
- {
294
- "internalType": "uint256",
295
- "name": "",
296
- "type": "uint256"
297
- }
298
- ],
299
- "stateMutability": "view",
300
- "type": "function"
301
- },
302
254
  {
303
255
  "inputs": [],
304
256
  "name": "feeBasisPoints",
@@ -331,6 +283,11 @@ __SHADOWPAY_ABI__ERC20__= json.loads("""[
331
283
  "internalType": "bytes32",
332
284
  "name": "id",
333
285
  "type": "bytes32"
286
+ },
287
+ {
288
+ "internalType": "address",
289
+ "name": "from",
290
+ "type": "address"
334
291
  }
335
292
  ],
336
293
  "name": "getChequeInfo",
@@ -344,6 +301,11 @@ __SHADOWPAY_ABI__ERC20__= json.loads("""[
344
301
  "internalType": "address payable[]",
345
302
  "name": "to",
346
303
  "type": "address[]"
304
+ },
305
+ {
306
+ "internalType": "bool",
307
+ "name": "claimed",
308
+ "type": "bool"
347
309
  }
348
310
  ],
349
311
  "stateMutability": "view",
@@ -394,38 +356,63 @@ __SHADOWPAY_ABI__ERC20__= json.loads("""[
394
356
  "internalType": "uint256",
395
357
  "name": "amountOut",
396
358
  "type": "uint256"
359
+ },
360
+ {
361
+ "internalType": "address",
362
+ "name": "spender",
363
+ "type": "address"
364
+ },
365
+ {
366
+ "internalType": "address",
367
+ "name": "receiver",
368
+ "type": "address"
369
+ },
370
+ {
371
+ "internalType": "bool",
372
+ "name": "claimed",
373
+ "type": "bool"
397
374
  }
398
375
  ],
399
376
  "stateMutability": "view",
400
377
  "type": "function"
401
378
  },
402
379
  {
403
- "inputs": [],
404
- "name": "getTreasery",
380
+ "inputs": [
381
+ {
382
+ "internalType": "bytes32",
383
+ "name": "id",
384
+ "type": "bytes32"
385
+ }
386
+ ],
387
+ "name": "getTokenChequeDetail",
405
388
  "outputs": [
406
389
  {
407
390
  "internalType": "address",
408
- "name": "",
391
+ "name": "spender",
409
392
  "type": "address"
393
+ },
394
+ {
395
+ "internalType": "address",
396
+ "name": "receiver",
397
+ "type": "address"
398
+ },
399
+ {
400
+ "internalType": "bool",
401
+ "name": "claimed",
402
+ "type": "bool"
410
403
  }
411
404
  ],
412
405
  "stateMutability": "view",
413
406
  "type": "function"
414
407
  },
415
408
  {
416
- "inputs": [
417
- {
418
- "internalType": "address",
419
- "name": "_addrr",
420
- "type": "address"
421
- }
422
- ],
423
- "name": "getUserChequeCount",
409
+ "inputs": [],
410
+ "name": "getTreasery",
424
411
  "outputs": [
425
412
  {
426
- "internalType": "uint256",
413
+ "internalType": "address",
427
414
  "name": "",
428
- "type": "uint256"
415
+ "type": "address"
429
416
  }
430
417
  ],
431
418
  "stateMutability": "view",
@@ -476,6 +463,78 @@ __SHADOWPAY_ABI__ERC20__= json.loads("""[
476
463
  "stateMutability": "view",
477
464
  "type": "function"
478
465
  },
466
+ {
467
+ "inputs": [
468
+ {
469
+ "internalType": "uint256",
470
+ "name": "_minFee",
471
+ "type": "uint256"
472
+ },
473
+ {
474
+ "internalType": "uint256",
475
+ "name": "_maxFees",
476
+ "type": "uint256"
477
+ },
478
+ {
479
+ "internalType": "uint256",
480
+ "name": "_minEth",
481
+ "type": "uint256"
482
+ },
483
+ {
484
+ "internalType": "uint256",
485
+ "name": "_baseFee",
486
+ "type": "uint256"
487
+ }
488
+ ],
489
+ "name": "setFees",
490
+ "outputs": [],
491
+ "stateMutability": "nonpayable",
492
+ "type": "function"
493
+ },
494
+ {
495
+ "inputs": [
496
+ {
497
+ "internalType": "uint256",
498
+ "name": "_TokenChequepercentage",
499
+ "type": "uint256"
500
+ },
501
+ {
502
+ "internalType": "uint256",
503
+ "name": "_SwapTokenChequepercentage",
504
+ "type": "uint256"
505
+ }
506
+ ],
507
+ "name": "setTokenFees",
508
+ "outputs": [],
509
+ "stateMutability": "nonpayable",
510
+ "type": "function"
511
+ },
512
+ {
513
+ "inputs": [
514
+ {
515
+ "internalType": "address",
516
+ "name": "_treaseryAddress",
517
+ "type": "address"
518
+ }
519
+ ],
520
+ "name": "setTreasery",
521
+ "outputs": [],
522
+ "stateMutability": "nonpayable",
523
+ "type": "function"
524
+ },
525
+ {
526
+ "inputs": [],
527
+ "name": "swapBasicPoints",
528
+ "outputs": [
529
+ {
530
+ "internalType": "uint256",
531
+ "name": "",
532
+ "type": "uint256"
533
+ }
534
+ ],
535
+ "stateMutability": "view",
536
+ "type": "function"
537
+ },
479
538
  {
480
539
  "inputs": [
481
540
  {
@@ -537,10 +596,44 @@ __SHADOWPAY_ABI__ERC20__= json.loads("""[
537
596
  ],
538
597
  "stateMutability": "view",
539
598
  "type": "function"
599
+ },
600
+ {
601
+ "inputs": [
602
+ {
603
+ "internalType": "uint256",
604
+ "name": "amount",
605
+ "type": "uint256"
606
+ },
607
+ {
608
+ "internalType": "address",
609
+ "name": "_to",
610
+ "type": "address"
611
+ }
612
+ ],
613
+ "name": "withdrawAmount",
614
+ "outputs": [],
615
+ "stateMutability": "nonpayable",
616
+ "type": "function"
617
+ },
618
+ {
619
+ "inputs": [],
620
+ "name": "withdrawFees",
621
+ "outputs": [],
622
+ "stateMutability": "nonpayable",
623
+ "type": "function"
540
624
  }
541
625
  ]""")
542
626
 
543
627
  __SHADOWPAY_ABI__ERC721__ = json.loads("""[]""")
544
628
  __SHADOWPAY_CONTRACT_ADDRESS__ERC721__ = {
545
629
  "0x1": "0x3c5b8d6f2e"
546
- }
630
+ }
631
+
632
+ SOLANA_SYSTEM_PROGRAMM = "11111111111111111111111111111111"
633
+ LAMPORTS_PER_SOL = 1_000_000_000
634
+ WRAPED_SOL = "So11111111111111111111111111111111111111112"
635
+ TOKEN_PROGRAM_ID = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
636
+ NATIVE_DECIMALS: int = 9
637
+ PROGRAM_ID = Pubkey.from_string("CrfYLvU4FdVjkBno2rRi6u5U6nGCykpQnQKSBg3uVXTw")
638
+
639
+ CONFIG_PDA=Pubkey.find_program_address([b"config"], PROGRAM_ID)
@@ -1,4 +1,4 @@
1
1
  from .erc20 import ERC20Token as ERC20
2
2
  from .erc721 import ERC721Token as ERC721
3
- from .sol import SolTokens as SPL
4
- __all__ = ["ERC20", "ERC721", "SPL"]
3
+ from .sol import SOL as sol
4
+ __all__ = ["ERC20", "ERC721", "sol"]
@@ -6,9 +6,10 @@ from shadowPaySDK.const import __ERC20_ABI__
6
6
 
7
7
 
8
8
  class ERC20Token:
9
- def __init__(self, w3:Web3, explorer: Optional[str] = None):
9
+ def __init__(self, w3: Optional[Web3] = None, explorer: Optional[str] = None):
10
10
  self.web3 = w3
11
11
  self.explorer = explorer
12
+
12
13
  self.address = None
13
14
  self.contract = None
14
15
 
@@ -21,7 +22,7 @@ class ERC20Token:
21
22
 
22
23
  def _ensure_contract(self):
23
24
  if not self.contract:
24
- raise ValueError("Token address is not set. Use set_token(token_address) first.")
25
+ raise ValueError("Token address is not set. Use set_params first.")
25
26
 
26
27
  def _format_tx(self, tx_hash: str) -> str:
27
28
  if self.explorer:
@@ -30,10 +31,9 @@ class ERC20Token:
30
31
  def gen_wallet(self) -> str:
31
32
  account = self.web3.eth.account.create()
32
33
  return account
33
- def get_decimals(self, token) -> int:
34
+ def get_decimals(self) -> int:
34
35
  self._ensure_contract()
35
- if token:
36
- self.set_params(token_address=token)
36
+
37
37
  return self.contract.functions.decimals().call()
38
38
 
39
39
  def get_symbol(self) -> str:
@@ -43,39 +43,39 @@ class ERC20Token:
43
43
  def get_balance(self, wallet_address: str) -> float:
44
44
  self._ensure_contract()
45
45
  raw = self.contract.functions.balanceOf(Web3.to_checksum_address(wallet_address)).call()
46
- return raw / (10 ** self.get_decimals())
46
+ return raw
47
47
 
48
- def allowance(self, owner: str, spender: str, token) -> float:
48
+
49
+ def allowance(self, owner: str, spender: str) -> float:
49
50
  self._ensure_contract()
50
51
  raw = self.contract.functions.allowance(
51
52
  Web3.to_checksum_address(owner),
52
53
  Web3.to_checksum_address(spender)
53
54
  ).call()
54
- return raw / (10 ** self.get_decimals(token))
55
+ return raw
55
56
 
56
- def ensure_allowance(self, private_key: str, spender: str, amount, token) -> Union[bool, str]:
57
+ def ensure_allowance(self, private_key: str, spender: str, amount, converted_amount: bool = False) -> Union[bool, str]:
57
58
  self._ensure_contract()
58
59
  account = self.web3.eth.account.from_key(private_key)
59
- current = self.allowance(account.address, spender, token)
60
+ current = self.allowance(account.address, spender)
60
61
  if current == amount:
61
62
  return True
62
- return self.approve(private_key, spender, amount, token)
63
+ return self.approve(private_key, spender, amount, conveted_amount=converted_amount)
63
64
 
64
65
  def transfer(self, private_key: str, to: str, amount: float) -> str:
65
66
  self._ensure_contract()
66
67
  account = self.web3.eth.account.from_key(private_key)
67
- decimals = self.get_decimals()
68
- value = int(amount * (10 ** decimals))
68
+
69
69
  estimated_gas = self.contract.functions.transfer(
70
70
  Web3.to_checksum_address(to),
71
- value
71
+ amount
72
72
  ).estimate_gas({
73
73
  'from': account.address,
74
74
  'gasPrice': self.web3.to_wei('5', 'gwei'),
75
75
  })
76
76
  txn = self.contract.functions.transfer(
77
77
  Web3.to_checksum_address(to),
78
- value
78
+ amount
79
79
  ).build_transaction({
80
80
  'from': account.address,
81
81
  'nonce': self.web3.eth.get_transaction_count(account.address),
@@ -87,28 +87,34 @@ class ERC20Token:
87
87
  tx_hash = self.web3.eth.send_raw_transaction(signed.raw_transaction)
88
88
  return self._format_tx(self.web3.to_hex(tx_hash))
89
89
 
90
- def approve(self, private_key: str, spender: str, amount: float, token) -> str:
90
+ def approve(self, spender: str, amount: float,address:Optional[str] = None, private_key: Optional[str] = None, conveted_amount: bool = True) -> str:
91
+
91
92
  self._ensure_contract()
92
- account = self.web3.eth.account.from_key(private_key)
93
- decimals = self.get_decimals(token=token)
94
- amount = int(amount * (10 ** decimals))
93
+ key = private_key
94
+
95
+ if key:
96
+ address = Web3.to_checksum_address(self.web3.eth.account.from_key(key).address)
95
97
 
98
+ elif self.address:
99
+ address = Web3.to_checksum_address(self.address)
100
+ else:
101
+ raise ValueError("No private key or address provided")
96
102
  txn = self.contract.functions.approve(
97
103
  Web3.to_checksum_address(spender),
98
104
  amount
99
105
  ).build_transaction({
100
- 'from': account.address,
101
- 'nonce': self.web3.eth.get_transaction_count(account.address),
106
+ 'from': address,
107
+ 'nonce': self.web3.eth.get_transaction_count(address),
102
108
  'gas': 60000,
103
109
 
104
110
  'gasPrice': self.web3.eth.gas_price,
105
111
  })
112
+
106
113
 
107
- signed = self.web3.eth.account.sign_transaction(txn, private_key)
114
+ signed = self.web3.eth.account.sign_transaction(txn, key)
108
115
  tx_hash = self.web3.eth.send_raw_transaction(signed.raw_transaction)
109
116
  tx_receipt = self.web3.eth.wait_for_transaction_receipt(tx_hash)
110
117
  if tx_receipt.status != 1:
111
118
  raise ValueError(f"aaprove fail.\n {self._format_tx(self.web3.to_hex(tx_hash))}")
112
-
113
- return f"approve: {self._format_tx(self.web3.to_hex(tx_hash))}"
119
+ return f"{self._format_tx(self.web3.to_hex(tx_hash))}"
114
120