shadowPaySDK 0.2.0.25__py3-none-any.whl → 0.2.0.27__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/const.py +5 -0
- shadowPaySDK/types/SOLcheque.py +150 -4
- {shadowpaysdk-0.2.0.25.dist-info → shadowpaysdk-0.2.0.27.dist-info}/METADATA +1 -1
- {shadowpaysdk-0.2.0.25.dist-info → shadowpaysdk-0.2.0.27.dist-info}/RECORD +7 -7
- {shadowpaysdk-0.2.0.25.dist-info → shadowpaysdk-0.2.0.27.dist-info}/WHEEL +0 -0
- {shadowpaysdk-0.2.0.25.dist-info → shadowpaysdk-0.2.0.27.dist-info}/licenses/LICENSE +0 -0
- {shadowpaysdk-0.2.0.25.dist-info → shadowpaysdk-0.2.0.27.dist-info}/top_level.txt +0 -0
shadowPaySDK/const.py
CHANGED
@@ -548,3 +548,8 @@ __SHADOWPAY_CONTRACT_ADDRESS__ERC721__ = {
|
|
548
548
|
"0x1": "0x3c5b8d6f2e"
|
549
549
|
}
|
550
550
|
|
551
|
+
SOLANA_SYSTEM_PROGRAMM = "11111111111111111111111111111111"
|
552
|
+
LAMPORTS_PER_SOL = 1_000_000_000
|
553
|
+
WRAPED_SOL = "So11111111111111111111111111111111111111112"
|
554
|
+
TOKEN_PROGRAM_ID = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
|
555
|
+
NATIVE_DECIMALS: int = 9
|
shadowPaySDK/types/SOLcheque.py
CHANGED
@@ -5,21 +5,167 @@ import solders
|
|
5
5
|
from shadowPaySDK.interface.sol import SOL
|
6
6
|
import solders
|
7
7
|
import spl.token.constants as spl_constants
|
8
|
+
from solana.rpc.api import Client
|
8
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, 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
|
50
|
+
|
51
|
+
PROGRAM_ID = Pubkey.from_string("5nfYDCgBgm72XdpYFEtWX2X1JQSyZdeBH2uuBZ6ZvQfi")
|
9
52
|
|
10
53
|
|
54
|
+
# PROGRAM_ID = "5nfYDCgBgm72XdpYFEtWX2X1JQSyZdeBH2uuBZ6ZvQfi"
|
55
|
+
|
11
56
|
class SOLCheque:
|
12
|
-
def __init__(self, rpc_url: str = "https://api.mainnet-beta.solana.com",
|
57
|
+
def __init__(self, rpc_url: str = "https://api.mainnet-beta.solana.com", key: Wallet = None):
|
13
58
|
self.rpc_url = rpc_url
|
14
|
-
self.
|
15
|
-
self.provider =
|
59
|
+
self.key = solders.keypair.Keypair.from_base58_string(key)
|
60
|
+
self.provider = Client(rpc_url)
|
16
61
|
self.WRAPED_SOL = spl_constants.WRAPPED_SOL_MINT # wrapped SOL token mint address
|
17
62
|
# self.idl = Idl.from_json(sol_interface.Idl) # Load the IDL for the program
|
18
63
|
def get(self, keypair = None):
|
19
64
|
pubkey = SOL.get_pubkey(KEYPAIR=solders.keypair.Keypair.from_base58_string(self.keystore))
|
20
65
|
|
21
66
|
return pubkey
|
22
|
-
|
67
|
+
def set_params(self, rpc_url = None, key = None):
|
68
|
+
if rpc_url:
|
69
|
+
self.rpc_url = rpc_url
|
70
|
+
self.provider = Client(rpc_url)
|
71
|
+
if key:
|
72
|
+
self.key = key
|
73
|
+
|
74
|
+
def init_cheque(self, cheque_amount, recipient: str, SPACE: int = 100):
|
75
|
+
"""
|
76
|
+
Initialize a cheque withc the specified amount and recipient.
|
77
|
+
"""
|
78
|
+
if not self.key:
|
79
|
+
raise ValueError("Keypair is not set. Please set the keypair before initializing a cheque.")
|
80
|
+
CHEQUE_PDA_SIGNATURE = None
|
81
|
+
CHEQUE_SPACE = SPACE
|
82
|
+
CHEQUE_RENT = self.provider.get_minimum_balance_for_rent_exemption(CHEQUE_SPACE)
|
83
|
+
print("Minimum balance for rent exemption:", CHEQUE_RENT.value / LAMPORTS_PER_SOL, "SOL")
|
84
|
+
sol = SOL(
|
85
|
+
KEYPAIR=self.key
|
86
|
+
)
|
87
|
+
payer = self.key
|
88
|
+
pubkey = self.key.pubkey()
|
89
|
+
newAcc = solders.keypair.Keypair()
|
90
|
+
newAccPubkey = newAcc.pubkey()
|
91
|
+
ix_create = create_account(
|
92
|
+
params=CreateAccountParams(
|
93
|
+
from_pubkey=pubkey,
|
94
|
+
to_pubkey=newAccPubkey,
|
95
|
+
lamports=CHEQUE_RENT.value,
|
96
|
+
space=CHEQUE_SPACE,
|
97
|
+
owner=PROGRAM_ID
|
98
|
+
)
|
99
|
+
)
|
100
|
+
recent_blockhash = self.provider.get_latest_blockhash().value.blockhash
|
101
|
+
message = Message(instructions=[ix_create], payer=pubkey)
|
102
|
+
|
103
|
+
t = Transaction(message=message, from_keypairs=[payer, newAcc], recent_blockhash=recent_blockhash)
|
104
|
+
r = self.provider.send_transaction(t,opts=TxOpts())
|
105
|
+
CHEQUE_PDA_SIGNATURE = r.value
|
106
|
+
CHEQUE_PDA = newAccPubkey
|
107
|
+
|
108
|
+
|
109
|
+
|
110
|
+
total_lamports = int(cheque_amount * LAMPORTS_PER_SOL)
|
111
|
+
|
112
|
+
|
113
|
+
r = Pubkey.from_string(recipient)
|
114
|
+
|
115
|
+
# 1 byte - tag
|
116
|
+
# 32 bytes - recipient pubkey
|
117
|
+
# 8 bytes - lamports (u64 LE)
|
118
|
+
data = bytes([0]) + bytes(r) + struct.pack("<Q", total_lamports)
|
119
|
+
|
120
|
+
# === Инструкция ===
|
121
|
+
|
122
|
+
|
123
|
+
instruction = Instruction(
|
124
|
+
program_id=PROGRAM_ID,
|
125
|
+
data=data,
|
126
|
+
accounts=[
|
127
|
+
AccountMeta(pubkey=pubkey, is_signer=True, is_writable=True), # payer
|
128
|
+
AccountMeta(pubkey=CHEQUE_PDA, is_signer=False, is_writable=True), # cheque PDA
|
129
|
+
AccountMeta(pubkey=Pubkey.from_string("11111111111111111111111111111111"), is_signer=False, is_writable=False)
|
130
|
+
|
131
|
+
]
|
132
|
+
)
|
133
|
+
|
134
|
+
recent_blockhash = self.provider.get_latest_blockhash().value.blockhash
|
135
|
+
message = Message(instructions=[instruction], payer=pubkey)
|
136
|
+
tx = Transaction(message=message, from_keypairs=[payer], recent_blockhash=recent_blockhash)
|
137
|
+
response = self.provider.send_transaction(tx,opts=TxOpts(skip_preflight=True))
|
138
|
+
data = {
|
139
|
+
"signature": response.value,
|
140
|
+
"amount": cheque_amount,
|
141
|
+
"create_pda": CHEQUE_PDA_SIGNATURE,
|
142
|
+
"cheque_pda": CHEQUE_PDA,
|
143
|
+
"rent_pda": CHEQUE_RENT.value / LAMPORTS_PER_SOL,
|
144
|
+
|
145
|
+
}
|
146
|
+
return data
|
147
|
+
|
148
|
+
def claim_cheque(self, pda_acc: str):
|
149
|
+
instruction_data = bytes([1])
|
150
|
+
payer = self.key
|
151
|
+
payer_pubkey = payer.pubkey()
|
152
|
+
|
153
|
+
|
154
|
+
ix = Instruction(
|
155
|
+
program_id=PROGRAM_ID,
|
156
|
+
data=instruction_data,
|
157
|
+
accounts = [
|
158
|
+
AccountMeta(pubkey=payer_pubkey, is_signer=True, is_writable=True),
|
159
|
+
AccountMeta(pubkey=Pubkey.from_string(pda_acc), is_signer=False, is_writable=True),
|
160
|
+
]
|
161
|
+
)
|
162
|
+
|
163
|
+
# Создаём и отправляем транзакцию
|
164
|
+
recent_blockhash = self.provider.get_latest_blockhash().value.blockhash
|
165
|
+
message = Message(instructions=[instruction_data], payer=payer_pubkey)
|
166
|
+
tx = Transaction(message=message, from_keypairs=[payer], recent_blockhash=recent_blockhash)
|
167
|
+
response = self.provider.send_transaction(tx,opts=TxOpts(skip_preflight=True))
|
168
|
+
return response.value
|
23
169
|
|
24
170
|
|
25
171
|
|
@@ -1,17 +1,17 @@
|
|
1
1
|
shadowPaySDK/__init__.py,sha256=CMwAuP_6hJN-WueU-XlTNta9Oyd28sFo8OojdgD_pxA,681
|
2
2
|
shadowPaySDK/api.py,sha256=cv5Z171cOh-Idi-lMA4AORzeGDPPrk8BCQ9e5V9MAaM,1461
|
3
|
-
shadowPaySDK/const.py,sha256=
|
3
|
+
shadowPaySDK/const.py,sha256=ogzTSFbJ_hQK49qEo2ZfxPiI_CTZLh7a706OKN41KYM,10140
|
4
4
|
shadowPaySDK/interface/__init__.py,sha256=ggSZCV22udnzXm_Wv_3x6VN3hNIAEiwgwHZc2Jwc688,146
|
5
5
|
shadowPaySDK/interface/erc20.py,sha256=7p8eU5LzhI2MsH80PZhq6IRhbfMGlNYucGl3OtyS9SI,4669
|
6
6
|
shadowPaySDK/interface/erc721.py,sha256=4AlWfDjrvl85wFocnN93j-oM54kTsLLwv9SdtcLj4eM,3094
|
7
7
|
shadowPaySDK/interface/sol.py,sha256=TDp62OtQkR8Wy9I4UBVmL_K_FQeMVS--Lojgbvq5T2E,8146
|
8
8
|
shadowPaySDK/types/EVMcheque.py,sha256=8M1EzpZGqf4uidrd9yDKiR7BvIl85p93A_9AMZtshSs,14570
|
9
|
-
shadowPaySDK/types/SOLcheque.py,sha256=
|
9
|
+
shadowPaySDK/types/SOLcheque.py,sha256=YN7bWqjWDL2FtZxqEOH91M9pT8B5DgSyiOUZbaFiCzI,6736
|
10
10
|
shadowPaySDK/types/__init__.py,sha256=sG6pNZfKGvENXqsnv6MrQtKrJ898fAXkMvAZY1k1-Qg,97
|
11
11
|
shadowPaySDK/utils/__init__.py,sha256=aja3iYO4rT-ptMM-pzw0GRFTziBdXdcEi-4kE84zH64,61
|
12
12
|
shadowPaySDK/utils/utils.py,sha256=g4bGvLDdjhNGsAj1eaZnNWFNaiN-cVhhM-5PrnG5aIQ,720
|
13
|
-
shadowpaysdk-0.2.0.
|
14
|
-
shadowpaysdk-0.2.0.
|
15
|
-
shadowpaysdk-0.2.0.
|
16
|
-
shadowpaysdk-0.2.0.
|
17
|
-
shadowpaysdk-0.2.0.
|
13
|
+
shadowpaysdk-0.2.0.27.dist-info/licenses/LICENSE,sha256=EG13vNmyBfkG3oKj40oOYfUGLKko8OouU6PfO6MlAk4,1066
|
14
|
+
shadowpaysdk-0.2.0.27.dist-info/METADATA,sha256=ysD2qNAuZO6VFiYRq5P64c54YIAjjiII5euIwkujV-E,964
|
15
|
+
shadowpaysdk-0.2.0.27.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
16
|
+
shadowpaysdk-0.2.0.27.dist-info/top_level.txt,sha256=RSJc73GEf31NMdZp9KovEduzfhm10eQ2t5GTZ44aN1U,13
|
17
|
+
shadowpaysdk-0.2.0.27.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|