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/interface/sol.py
CHANGED
@@ -1,17 +1,29 @@
|
|
1
1
|
import asyncio
|
2
|
+
import solana
|
2
3
|
from solana.rpc.async_api import AsyncClient, GetTokenAccountsByOwnerResp
|
4
|
+
from solders.transaction import Transaction
|
5
|
+
from solders.system_program import TransferParams as p
|
3
6
|
import spl
|
4
7
|
import spl.token
|
5
8
|
import spl.token.constants
|
6
|
-
from spl.token.instructions import get_associated_token_address, create_associated_token_account, transfer, close_account
|
9
|
+
from spl.token.instructions import get_associated_token_address, create_associated_token_account, transfer, close_account, TransferParams
|
10
|
+
from solders.system_program import transfer as ts
|
11
|
+
from solders.system_program import TransferParams as tsf
|
7
12
|
from spl.token.constants import TOKEN_PROGRAM_ID, ASSOCIATED_TOKEN_PROGRAM_ID
|
8
|
-
from solana.constants import *
|
9
13
|
from solana.rpc.types import TxOpts, TokenAccountOpts
|
10
14
|
from solana.rpc.types import TxOpts
|
11
15
|
import solders
|
12
|
-
from solders.
|
13
|
-
|
14
|
-
from solders.
|
16
|
+
from solders.message import Message
|
17
|
+
|
18
|
+
# from solders.pubkey import Pubkey
|
19
|
+
# from solders.keypair import Keypair
|
20
|
+
# from solders.signature import Signature
|
21
|
+
# from solders.transaction import Transaction
|
22
|
+
from spl.token.async_client import AsyncToken
|
23
|
+
|
24
|
+
|
25
|
+
from solana.rpc.commitment import Confirmed
|
26
|
+
from solana.rpc.async_api import AsyncClient
|
15
27
|
import anchorpy
|
16
28
|
from anchorpy import Provider, Wallet, Idl
|
17
29
|
from typing import Optional, Union
|
@@ -20,44 +32,40 @@ import httpx
|
|
20
32
|
import base64
|
21
33
|
import re
|
22
34
|
|
23
|
-
|
24
|
-
|
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)
|
35
|
+
|
36
|
+
LAMPORTS_PER_SOL = 1_000_000_000 # 1 SOL = 1,000,000,000 lamports
|
33
37
|
|
34
38
|
class SOL:
|
35
|
-
|
36
|
-
def __init__(self, rpc_url = "https://api.mainnet-beta.solana.com", KEYPAIR: Optional[Union[str, Keypair]] = None):
|
39
|
+
def __init__(self, rpc_url = "https://api.mainnet-beta.solana.com", KEYPAIR: Optional[Union[str, solders.keypair.Keypair]] = None,TOKEN_MINT: Optional[str] = None):
|
37
40
|
self.rpc_url = rpc_url
|
41
|
+
|
38
42
|
self.client = AsyncClient(rpc_url)
|
39
43
|
self.KEYPAIR = None
|
40
|
-
|
44
|
+
self.PROGRAM_ID = TOKEN_PROGRAM_ID # Default to the SPL Token Program ID
|
45
|
+
self.TOKEN_MINT = TOKEN_MINT
|
46
|
+
self.WRAPED_SOL_ID = spl.token.constants.WRAPPED_SOL_MINT
|
41
47
|
if KEYPAIR:
|
42
48
|
self.set_keypair(KEYPAIR)
|
43
49
|
|
44
|
-
def set_keypair(self, KEYPAIR: Union[str, Keypair]):
|
50
|
+
def set_keypair(self, KEYPAIR: Union[str, solders.keypair.Keypair]):
|
45
51
|
if isinstance(KEYPAIR, str):
|
46
52
|
try:
|
47
|
-
self.KEYPAIR = Keypair.from_base58_string(KEYPAIR)
|
53
|
+
self.KEYPAIR = solders.keypair.Keypair.from_base58_string(KEYPAIR)
|
48
54
|
except Exception as e:
|
49
55
|
raise ValueError(f"Invalid Keypair string: {e}")
|
50
|
-
elif isinstance(KEYPAIR, Keypair):
|
56
|
+
elif isinstance(KEYPAIR, solders.keypair.Keypair):
|
51
57
|
self.KEYPAIR = KEYPAIR
|
52
58
|
else:
|
53
59
|
raise ValueError("KEYPAIR must be a Keypair instance or a base58 encoded string.")
|
54
60
|
|
55
|
-
def set_params(self, rpc_url: Optional[str] = None, KEYPAIR: Optional[Union[str, Keypair]] = None):
|
61
|
+
def set_params(self, rpc_url: Optional[str] = None, KEYPAIR: Optional[Union[str, solders.keypair.Keypair]] = None,TOKEN_MINT: Optional[str] = None):
|
56
62
|
if rpc_url:
|
57
63
|
self.rpc_url = rpc_url
|
58
64
|
self.client = AsyncClient(rpc_url)
|
59
65
|
if KEYPAIR:
|
60
66
|
self.set_keypair(KEYPAIR)
|
67
|
+
if TOKEN_MINT:
|
68
|
+
self.TOKEN_MINT = TOKEN_MINT
|
61
69
|
|
62
70
|
def get_pubkey(self, returnString: Optional[bool] = None):
|
63
71
|
|
@@ -72,7 +80,7 @@ class SOL:
|
|
72
80
|
raise ValueError("Keypair not set")
|
73
81
|
|
74
82
|
def gen_wallet(self):
|
75
|
-
return Keypair()
|
83
|
+
return solders.keypair.Keypair()
|
76
84
|
async def get_balance(self):
|
77
85
|
resp = await self.client.get_balance(self.get_pubkey())
|
78
86
|
lamports = resp.value
|
@@ -107,24 +115,19 @@ class SOL:
|
|
107
115
|
ui_amount = parsed["tokenAmount"]["uiAmount"]
|
108
116
|
token_data[mint] = {"amount": ui_amount}
|
109
117
|
|
110
|
-
|
118
|
+
|
111
119
|
|
112
|
-
return
|
113
|
-
async def is_connected(self):
|
114
|
-
return await self.client.is_connected()
|
120
|
+
return token_data
|
115
121
|
|
116
|
-
async def close(self):
|
117
|
-
await self.client.close()
|
118
|
-
|
119
122
|
async def fetch_metadata_raw(self,mint_address: str):
|
120
|
-
METADATA_PROGRAM_ID = Pubkey.from_string("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s")
|
121
|
-
mint = Pubkey.from_string(mint_address)
|
123
|
+
METADATA_PROGRAM_ID = solders.pubkey.Pubkey.from_string("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s")
|
124
|
+
mint = solders.pubkey.Pubkey.from_string(mint_address)
|
122
125
|
seeds = [
|
123
126
|
b"metadata",
|
124
127
|
bytes(METADATA_PROGRAM_ID),
|
125
128
|
bytes(mint),
|
126
129
|
]
|
127
|
-
pda, _ = Pubkey.find_program_address(seeds, METADATA_PROGRAM_ID)
|
130
|
+
pda, _ = solders.pubkey.Pubkey.find_program_address(seeds, METADATA_PROGRAM_ID)
|
128
131
|
|
129
132
|
payload = {
|
130
133
|
"jsonrpc": "2.0",
|
@@ -137,7 +140,7 @@ class SOL:
|
|
137
140
|
}
|
138
141
|
|
139
142
|
async with httpx.AsyncClient() as client:
|
140
|
-
r = await client.post(
|
143
|
+
r = await client.post(self.rpc_url, json=payload)
|
141
144
|
data = r.json()
|
142
145
|
|
143
146
|
if not data["result"]["value"]:
|
@@ -151,12 +154,71 @@ class SOL:
|
|
151
154
|
return {
|
152
155
|
"mint": mint_address,
|
153
156
|
"name": name,
|
154
|
-
}
|
155
157
|
|
158
|
+
}
|
159
|
+
async def transfer_token(self, to: str, amount: float):
|
160
|
+
|
161
|
+
if not self.TOKEN_MINT:
|
162
|
+
raise ValueError("not set TOKEN_MINT.")
|
163
|
+
if not self.KEYPAIR:
|
164
|
+
raise ValueError("not set KEYPAIR.")
|
165
|
+
|
166
|
+
sender_pubkey = self.get_pubkey()
|
167
|
+
receiver_pubkey = solders.pubkey.Pubkey.from_string(to)
|
168
|
+
token_pubkey = solders.pubkey.Pubkey.from_string(self.TOKEN_MINT)
|
169
|
+
|
170
|
+
token = AsyncToken(self.client, token_pubkey, TOKEN_PROGRAM_ID, self.KEYPAIR)
|
171
|
+
sender_ata = get_associated_token_address(sender_pubkey, token_pubkey)
|
172
|
+
receiver_ata = get_associated_token_address(receiver_pubkey, token_pubkey)
|
173
|
+
|
174
|
+
tx = Transaction()
|
175
|
+
|
176
|
+
res = await self.client.get_account_info(receiver_ata)
|
177
|
+
if res.value is None:
|
178
|
+
tx.add(
|
179
|
+
create_associated_token_account(
|
180
|
+
payer=sender_pubkey,
|
181
|
+
owner=receiver_pubkey,
|
182
|
+
mint=token_pubkey
|
183
|
+
)
|
184
|
+
)
|
185
|
+
|
186
|
+
decimals = (await token.get_mint_info()).decimals
|
187
|
+
real_amount = int(amount * (10 ** decimals))
|
188
|
+
params = TransferParams(
|
189
|
+
program_id=TOKEN_PROGRAM_ID,
|
190
|
+
source=sender_ata,
|
191
|
+
dest=receiver_ata,
|
192
|
+
owner=sender_pubkey,
|
193
|
+
amount=real_amount
|
194
|
+
)
|
195
|
+
|
196
|
+
tx.add(transfer(params))
|
197
|
+
|
198
|
+
resp = await self.client.send_transaction(tx, self.KEYPAIR, opts=TxOpts(skip_preflight=True, preflight_commitment=Confirmed))
|
199
|
+
return resp.value
|
200
|
+
|
201
|
+
|
202
|
+
async def transfer_native(self, to:str, amount: int):
|
203
|
+
if not self.KEYPAIR:
|
204
|
+
raise ValueError("not set KEYPAIR.")
|
205
|
+
|
206
|
+
sender_pubkey = self.get_pubkey()
|
207
|
+
receiver_pubkey = solders.pubkey.Pubkey.from_string(to)
|
208
|
+
ixns = [
|
209
|
+
ts(tsf(
|
210
|
+
from_pubkey=sender_pubkey,
|
211
|
+
to_pubkey=receiver_pubkey,
|
212
|
+
lamports=int(amount * LAMPORTS_PER_SOL)
|
213
|
+
))
|
214
|
+
]
|
215
|
+
msg = Message(ixns, self.get_pubkey())
|
216
|
+
latest_blockhash_resp = await self.client.get_latest_blockhash()
|
156
217
|
|
218
|
+
blockhash_str = latest_blockhash_resp.value.blockhash
|
219
|
+
tx = Transaction([self.KEYPAIR], msg, blockhash_str)
|
220
|
+
resp = await self.client.send_transaction(tx)
|
221
|
+
return resp.value
|
157
222
|
|
158
223
|
|
159
224
|
|
160
|
-
if __name__ == "__main__":
|
161
|
-
newKeypair = Keypair()
|
162
|
-
print("New Keypair:", newKeypair)
|