shadowPaySDK 0.2.0.5__tar.gz → 0.2.0.7__tar.gz
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-0.2.0.5 → shadowpaysdk-0.2.0.7}/PKG-INFO +1 -1
- {shadowpaysdk-0.2.0.5 → shadowpaysdk-0.2.0.7}/setup.py +1 -1
- {shadowpaysdk-0.2.0.5 → shadowpaysdk-0.2.0.7}/shadowPaySDK/__init__.py +1 -2
- {shadowpaysdk-0.2.0.5 → shadowpaysdk-0.2.0.7}/shadowPaySDK/interface/__init__.py +2 -2
- {shadowpaysdk-0.2.0.5 → shadowpaysdk-0.2.0.7}/shadowPaySDK/interface/sol.py +60 -16
- {shadowpaysdk-0.2.0.5 → shadowpaysdk-0.2.0.7}/shadowPaySDK/types/EVMcheque.py +46 -1
- {shadowpaysdk-0.2.0.5 → shadowpaysdk-0.2.0.7}/shadowPaySDK.egg-info/PKG-INFO +1 -1
- {shadowpaysdk-0.2.0.5 → shadowpaysdk-0.2.0.7}/LICENSE +0 -0
- {shadowpaysdk-0.2.0.5 → shadowpaysdk-0.2.0.7}/README.md +0 -0
- {shadowpaysdk-0.2.0.5 → shadowpaysdk-0.2.0.7}/setup.cfg +0 -0
- {shadowpaysdk-0.2.0.5 → shadowpaysdk-0.2.0.7}/shadowPaySDK/api.py +0 -0
- {shadowpaysdk-0.2.0.5 → shadowpaysdk-0.2.0.7}/shadowPaySDK/const.py +0 -0
- {shadowpaysdk-0.2.0.5 → shadowpaysdk-0.2.0.7}/shadowPaySDK/interface/erc20.py +0 -0
- {shadowpaysdk-0.2.0.5 → shadowpaysdk-0.2.0.7}/shadowPaySDK/interface/erc721.py +0 -0
- {shadowpaysdk-0.2.0.5 → shadowpaysdk-0.2.0.7}/shadowPaySDK/types/SOLcheque.py +0 -0
- {shadowpaysdk-0.2.0.5 → shadowpaysdk-0.2.0.7}/shadowPaySDK/types/__init__.py +0 -0
- {shadowpaysdk-0.2.0.5 → shadowpaysdk-0.2.0.7}/shadowPaySDK/utils/__init__.py +0 -0
- {shadowpaysdk-0.2.0.5 → shadowpaysdk-0.2.0.7}/shadowPaySDK/utils/utils.py +0 -0
- {shadowpaysdk-0.2.0.5 → shadowpaysdk-0.2.0.7}/shadowPaySDK.egg-info/SOURCES.txt +0 -0
- {shadowpaysdk-0.2.0.5 → shadowpaysdk-0.2.0.7}/shadowPaySDK.egg-info/dependency_links.txt +0 -0
- {shadowpaysdk-0.2.0.5 → shadowpaysdk-0.2.0.7}/shadowPaySDK.egg-info/requires.txt +0 -0
- {shadowpaysdk-0.2.0.5 → shadowpaysdk-0.2.0.7}/shadowPaySDK.egg-info/top_level.txt +0 -0
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
|
|
2
2
|
|
3
3
|
setup(
|
4
4
|
name='shadowPaySDK',
|
5
|
-
version='0.2.0.
|
5
|
+
version='0.2.0.7',
|
6
6
|
description='ShadowPay SDK for ERC20/ERC721 and P2P smart contract interaction',
|
7
7
|
long_description=open('README.md').read(),
|
8
8
|
long_description_content_type='text/markdown',
|
@@ -1,8 +1,7 @@
|
|
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
|
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__
|
@@ -12,6 +12,12 @@ import solders
|
|
12
12
|
from solders.pubkey import Pubkey
|
13
13
|
from solders.keypair import Keypair
|
14
14
|
from solders.signature import Signature
|
15
|
+
from solders.transaction import Transaction
|
16
|
+
from spl.token.async_client import AsyncToken
|
17
|
+
|
18
|
+
|
19
|
+
from solana.rpc.commitment import Confirmed
|
20
|
+
from solana.rpc.async_api import AsyncClient
|
15
21
|
import anchorpy
|
16
22
|
from anchorpy import Provider, Wallet, Idl
|
17
23
|
from typing import Optional, Union
|
@@ -20,24 +26,16 @@ import httpx
|
|
20
26
|
import base64
|
21
27
|
import re
|
22
28
|
|
23
|
-
class SolTokens:
|
24
|
-
def __init__(self, rpc_url: str = "https://api.mainnet-beta.solana.com"):
|
25
|
-
self.rpc_url = rpc_url
|
26
|
-
self.client = AsyncClient(rpc_url)
|
27
|
-
self.PROGRAM_ID = TOKEN_PROGRAM_ID # Default to the SPL Token Program ID
|
28
|
-
self.WRAPED_SOL_ID = spl.token.constants.WRAPPED_SOL_MINT
|
29
|
-
def set_params(self, rpc_url: Optional[str] = None, PROGRAM_ID: Optional[str] = None):
|
30
|
-
if rpc_url:
|
31
|
-
self.rpc_url = rpc_url
|
32
|
-
self.client = AsyncClient(rpc_url)
|
33
29
|
|
34
30
|
class SOL:
|
35
31
|
|
36
|
-
def __init__(self, rpc_url = "https://api.mainnet-beta.solana.com", KEYPAIR: Optional[Union[str, Keypair]] = None):
|
32
|
+
def __init__(self, rpc_url = "https://api.mainnet-beta.solana.com", KEYPAIR: Optional[Union[str, Keypair]] = None,TOKEN_MINT: Optional[str] = None):
|
37
33
|
self.rpc_url = rpc_url
|
38
34
|
self.client = AsyncClient(rpc_url)
|
39
35
|
self.KEYPAIR = None
|
40
|
-
|
36
|
+
self.PROGRAM_ID = TOKEN_PROGRAM_ID # Default to the SPL Token Program ID
|
37
|
+
self.TOKEN_MINT = TOKEN_MINT
|
38
|
+
self.WRAPED_SOL_ID = spl.token.constants.WRAPPED_SOL_MINT
|
41
39
|
if KEYPAIR:
|
42
40
|
self.set_keypair(KEYPAIR)
|
43
41
|
|
@@ -52,12 +50,14 @@ class SOL:
|
|
52
50
|
else:
|
53
51
|
raise ValueError("KEYPAIR must be a Keypair instance or a base58 encoded string.")
|
54
52
|
|
55
|
-
def set_params(self, rpc_url: Optional[str] = None, KEYPAIR: Optional[Union[str, Keypair]] = None):
|
53
|
+
def set_params(self, rpc_url: Optional[str] = None, KEYPAIR: Optional[Union[str, Keypair]] = None,TOKEN_MINT: Optional[str] = None):
|
56
54
|
if rpc_url:
|
57
55
|
self.rpc_url = rpc_url
|
58
56
|
self.client = AsyncClient(rpc_url)
|
59
57
|
if KEYPAIR:
|
60
58
|
self.set_keypair(KEYPAIR)
|
59
|
+
if TOKEN_MINT:
|
60
|
+
self.TOKEN_MINT = TOKEN_MINT
|
61
61
|
|
62
62
|
def get_pubkey(self, returnString: Optional[bool] = None):
|
63
63
|
|
@@ -107,9 +107,9 @@ class SOL:
|
|
107
107
|
ui_amount = parsed["tokenAmount"]["uiAmount"]
|
108
108
|
token_data[mint] = {"amount": ui_amount}
|
109
109
|
|
110
|
-
|
110
|
+
|
111
111
|
|
112
|
-
return
|
112
|
+
return token_data
|
113
113
|
async def is_connected(self):
|
114
114
|
return await self.client.is_connected()
|
115
115
|
|
@@ -137,7 +137,7 @@ class SOL:
|
|
137
137
|
}
|
138
138
|
|
139
139
|
async with httpx.AsyncClient() as client:
|
140
|
-
r = await client.post(
|
140
|
+
r = await client.post(self.rpc_url, json=payload)
|
141
141
|
data = r.json()
|
142
142
|
|
143
143
|
if not data["result"]["value"]:
|
@@ -151,7 +151,51 @@ class SOL:
|
|
151
151
|
return {
|
152
152
|
"mint": mint_address,
|
153
153
|
"name": name,
|
154
|
+
|
155
|
+
|
154
156
|
}
|
157
|
+
async def transfer_token(self, to: str, amount: float):
|
158
|
+
|
159
|
+
if not self.TOKEN_MINT:
|
160
|
+
raise ValueError("not set TOKEN_MINT.")
|
161
|
+
if not self.KEYPAIR:
|
162
|
+
raise ValueError("not set KEYPAIR.")
|
163
|
+
|
164
|
+
sender_pubkey = self.get_pubkey()
|
165
|
+
receiver_pubkey = Pubkey.from_string(to)
|
166
|
+
token_pubkey = Pubkey.from_string(self.TOKEN_MINT)
|
167
|
+
|
168
|
+
token = AsyncToken(self.client, token_pubkey, TOKEN_PROGRAM_ID, self.KEYPAIR)
|
169
|
+
sender_ata = get_associated_token_address(sender_pubkey, token_pubkey)
|
170
|
+
receiver_ata = get_associated_token_address(receiver_pubkey, token_pubkey)
|
171
|
+
|
172
|
+
tx = Transaction()
|
173
|
+
|
174
|
+
res = await self.client.get_account_info(receiver_ata)
|
175
|
+
if res.value is None:
|
176
|
+
tx.add(
|
177
|
+
create_associated_token_account(
|
178
|
+
payer=sender_pubkey,
|
179
|
+
owner=receiver_pubkey,
|
180
|
+
mint=token_pubkey
|
181
|
+
)
|
182
|
+
)
|
183
|
+
|
184
|
+
decimals = (await token.get_mint_info()).decimals
|
185
|
+
real_amount = int(amount * (10 ** decimals))
|
186
|
+
|
187
|
+
tx.add(
|
188
|
+
transfer(
|
189
|
+
source=sender_ata,
|
190
|
+
dest=receiver_ata,
|
191
|
+
owner=sender_pubkey,
|
192
|
+
amount=real_amount,
|
193
|
+
program_id=TOKEN_PROGRAM_ID,
|
194
|
+
)
|
195
|
+
)
|
196
|
+
|
197
|
+
resp = await self.client.send_transaction(tx, self.KEYPAIR, opts=TxOpts(skip_preflight=True, preflight_commitment=Confirmed))
|
198
|
+
return resp.value
|
155
199
|
|
156
200
|
|
157
201
|
|
@@ -262,6 +262,47 @@ class Cheque:
|
|
262
262
|
"hash": txn_hash.hex(),
|
263
263
|
"chequeId": cheque_id
|
264
264
|
}
|
265
|
+
|
266
|
+
async def CashOutSwapCheque(self, cheque_id: str, private_key: Optional[str] = None):
|
267
|
+
swapDetail = await self.getSwaoDetail(cheque_id)
|
268
|
+
print(swapDetail)
|
269
|
+
if private_key is None:
|
270
|
+
private_key = self.private_key
|
271
|
+
token_out = swapDetail["tokenOut"]
|
272
|
+
amount_out = swapDetail["amountOut"]
|
273
|
+
erc20 = shadowPaySDK.ERC20Token(w3=self.w3)
|
274
|
+
erc20.set_params(token_address=token_out)
|
275
|
+
encure_allowance = erc20.ensure_allowance(
|
276
|
+
private_key=private_key,
|
277
|
+
spender=self.contract.address,
|
278
|
+
amount=amount_out,
|
279
|
+
)
|
280
|
+
estimated_gas = self.contract.functions.CashOutSwapCheque(
|
281
|
+
Web3.to_bytes(hexstr=cheque_id)
|
282
|
+
).estimate_gas({
|
283
|
+
'from': self.w3.eth.account.from_key(private_key).address,
|
284
|
+
'gasPrice': self.w3.eth.gas_price
|
285
|
+
})
|
286
|
+
swa = self.contract.functions.CashOutSwapCheque(
|
287
|
+
Web3.to_bytes(hexstr=cheque_id)
|
288
|
+
).build_transaction({
|
289
|
+
'from': self.w3.eth.account.from_key(private_key).address,
|
290
|
+
'nonce': self.w3.eth.get_transaction_count(self.w3.eth.account.from_key(private_key).address),
|
291
|
+
'gas': 300_000,
|
292
|
+
'gasPrice': self.w3.eth.gas_price
|
293
|
+
})
|
294
|
+
signed_txn = self.w3.eth.account.sign_transaction(swa, private_key=private_key)
|
295
|
+
tx_hash = self.w3.eth.send_raw_transaction(signed_txn.raw_transaction)
|
296
|
+
receipt = self.w3.eth.wait_for_transaction_receipt(tx_hash)
|
297
|
+
if receipt.status != 1:
|
298
|
+
return False
|
299
|
+
return {
|
300
|
+
"hash": tx_hash.hex(),
|
301
|
+
}
|
302
|
+
|
303
|
+
|
304
|
+
|
305
|
+
|
265
306
|
async def getComunityPool(self):
|
266
307
|
# fee = self.contract.functions.getCollectedFee().call()
|
267
308
|
fee = 50000000000000
|
@@ -273,7 +314,11 @@ class Cheque:
|
|
273
314
|
return self.contract.functions.getTreasery().call()
|
274
315
|
async def getSwaoDetail(self, cheque_id: str):
|
275
316
|
cheque_id_bytes = Web3.to_bytes(hexstr=cheque_id)
|
276
|
-
|
317
|
+
s = self.contract.functions.getSwapDetail(cheque_id_bytes).call()
|
318
|
+
return{
|
319
|
+
"tokenOut": s[0],
|
320
|
+
"amountOut": s[1],
|
321
|
+
}
|
277
322
|
class NFTcheque:
|
278
323
|
def __init__(self, w3:Web3, token:str, amount:int, spender:str):
|
279
324
|
self.w3 = w3
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|