Skip to content

Commit

Permalink
py: Bump solana packages (#55)
Browse files Browse the repository at this point in the history
#### Problem

The python client is still on older deps for solana and solders.

#### Summary of changes

Bump them all and update as needed!
  • Loading branch information
joncinque authored Jan 22, 2025
1 parent 611b55b commit 80ee575
Show file tree
Hide file tree
Showing 6 changed files with 454 additions and 395 deletions.
6 changes: 3 additions & 3 deletions clients/py/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ httpx==0.28.1
idna==3.10
jsonalias==0.1.1
sniffio==1.3.1
solana==0.34.2
solders==0.21.0
solana==0.36.2
solders==0.23.0
typing_extensions==4.12.2
websockets==11.0.3
websockets==13.1.0
71 changes: 38 additions & 33 deletions clients/py/spl_token/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from solana.rpc.async_api import AsyncClient
from solana.rpc.commitment import Confirmed
from solana.rpc.types import TxOpts
from solana.transaction import Transaction
from solders.transaction import Transaction
import solders.system_program as sys

from spl.token.constants import TOKEN_PROGRAM_ID
Expand All @@ -21,42 +21,47 @@ async def create_associated_token_account(
owner: Pubkey,
mint: Pubkey
) -> Pubkey:
txn = Transaction(fee_payer=payer.pubkey())
create_txn = spl_token.create_associated_token_account(
payer=payer.pubkey(), owner=owner, mint=mint
)
txn.add(create_txn)
recent_blockhash = (await client.get_latest_blockhash()).value.blockhash
await client.send_transaction(txn, payer, recent_blockhash=recent_blockhash, opts=OPTS)
return create_txn.accounts[1].pubkey
ix = spl_token.create_associated_token_account(
payer=payer.pubkey(), owner=owner, mint=mint
)
txn = Transaction.new_signed_with_payer(
[ix],
signing_keypairs=[payer],
payer=payer.pubkey(),
recent_blockhash=recent_blockhash
)
await client.send_transaction(txn, opts=OPTS)
return ix.accounts[1].pubkey


async def create_mint(client: AsyncClient, payer: Keypair, mint: Keypair, mint_authority: Pubkey):
mint_balance = await AsyncToken.get_min_balance_rent_for_exempt_for_mint(client)
print(f"Creating pool token mint {mint.pubkey()}")
txn = Transaction(fee_payer=payer.pubkey())
txn.add(
sys.create_account(
sys.CreateAccountParams(
from_pubkey=payer.pubkey(),
to_pubkey=mint.pubkey(),
lamports=mint_balance,
space=MINT_LAYOUT.sizeof(),
owner=TOKEN_PROGRAM_ID,
)
)
)
txn.add(
spl_token.initialize_mint(
spl_token.InitializeMintParams(
program_id=TOKEN_PROGRAM_ID,
mint=mint.pubkey(),
decimals=9,
mint_authority=mint_authority,
freeze_authority=None,
mint_balance = await AsyncToken.get_min_balance_rent_for_exempt_for_mint(client)
recent_blockhash = (await client.get_latest_blockhash()).value.blockhash
txn = Transaction.new_signed_with_payer(
[
sys.create_account(
sys.CreateAccountParams(
from_pubkey=payer.pubkey(),
to_pubkey=mint.pubkey(),
lamports=mint_balance,
space=MINT_LAYOUT.sizeof(),
owner=TOKEN_PROGRAM_ID,
)
),
spl_token.initialize_mint(
spl_token.InitializeMintParams(
program_id=TOKEN_PROGRAM_ID,
mint=mint.pubkey(),
decimals=9,
mint_authority=mint_authority,
freeze_authority=None,
)
)
)
],
payer=payer.pubkey(),
recent_blockhash=recent_blockhash,
signing_keypairs=[payer, mint],
)
recent_blockhash = (await client.get_latest_blockhash()).value.blockhash
await client.send_transaction(
txn, payer, mint, recent_blockhash=recent_blockhash, opts=OPTS)
await client.send_transaction(txn, opts=OPTS)
106 changes: 57 additions & 49 deletions clients/py/stake/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from solana.rpc.commitment import Confirmed
from solana.rpc.types import TxOpts
from solders.sysvar import CLOCK, STAKE_HISTORY
from solana.transaction import Transaction
from solders.transaction import Transaction

from stake.constants import STAKE_LEN, STAKE_PROGRAM_ID, SYSVAR_STAKE_CONFIG_ID
from stake.state import Authorized, Lockup, StakeAuthorize
Expand All @@ -19,73 +19,81 @@
async def create_stake(client: AsyncClient, payer: Keypair, stake: Keypair, authority: Pubkey, lamports: int):
print(f"Creating stake {stake.pubkey()}")
resp = await client.get_minimum_balance_for_rent_exemption(STAKE_LEN)
txn = Transaction(fee_payer=payer.pubkey())
txn.add(
sys.create_account(
sys.CreateAccountParams(
from_pubkey=payer.pubkey(),
to_pubkey=stake.pubkey(),
lamports=resp.value + lamports,
space=STAKE_LEN,
owner=STAKE_PROGRAM_ID,
)
)
)
txn.add(
st.initialize(
st.InitializeParams(
stake=stake.pubkey(),
authorized=Authorized(
staker=authority,
withdrawer=authority,
),
lockup=Lockup(
unix_timestamp=0,
epoch=0,
custodian=SYSTEM_PROGRAM_ID,
recent_blockhash = (await client.get_latest_blockhash()).value.blockhash
txn = Transaction.new_signed_with_payer(
[
sys.create_account(
sys.CreateAccountParams(
from_pubkey=payer.pubkey(),
to_pubkey=stake.pubkey(),
lamports=resp.value + lamports,
space=STAKE_LEN,
owner=STAKE_PROGRAM_ID,
)
),
st.initialize(
st.InitializeParams(
stake=stake.pubkey(),
authorized=Authorized(
staker=authority,
withdrawer=authority,
),
lockup=Lockup(
unix_timestamp=0,
epoch=0,
custodian=SYSTEM_PROGRAM_ID,
)
)
)
)
],
payer=payer.pubkey(),
signing_keypairs=[payer, stake],
recent_blockhash=recent_blockhash,
)
recent_blockhash = (await client.get_latest_blockhash()).value.blockhash
await client.send_transaction(txn, payer, stake, recent_blockhash=recent_blockhash, opts=OPTS)
await client.send_transaction(txn, opts=OPTS)


async def delegate_stake(client: AsyncClient, payer: Keypair, staker: Keypair, stake: Pubkey, vote: Pubkey):
txn = Transaction(fee_payer=payer.pubkey())
txn.add(
st.delegate_stake(
st.DelegateStakeParams(
stake=stake,
vote=vote,
clock_sysvar=CLOCK,
stake_history_sysvar=STAKE_HISTORY,
stake_config_id=SYSVAR_STAKE_CONFIG_ID,
staker=staker.pubkey(),
recent_blockhash = (await client.get_latest_blockhash()).value.blockhash
signers = [payer, staker] if payer.pubkey() != staker.pubkey() else [payer]
txn = Transaction.new_signed_with_payer(
[
st.delegate_stake(
st.DelegateStakeParams(
stake=stake,
vote=vote,
clock_sysvar=CLOCK,
stake_history_sysvar=STAKE_HISTORY,
stake_config_id=SYSVAR_STAKE_CONFIG_ID,
staker=staker.pubkey(),
)
)
)
],
payer=payer.pubkey(),
signing_keypairs=signers,
recent_blockhash=recent_blockhash,
)
signers = [payer, staker] if payer.pubkey() != staker.pubkey() else [payer]
recent_blockhash = (await client.get_latest_blockhash()).value.blockhash
await client.send_transaction(txn, *signers, recent_blockhash=recent_blockhash, opts=OPTS)
await client.send_transaction(txn, opts=OPTS)


async def authorize(
client: AsyncClient, payer: Keypair, authority: Keypair, stake: Pubkey,
new_authority: Pubkey, stake_authorize: StakeAuthorize
):
txn = Transaction(fee_payer=payer.pubkey())
txn.add(
st.authorize(
signers = [payer, authority] if payer.pubkey() != authority.pubkey() else [payer]
recent_blockhash = (await client.get_latest_blockhash()).value.blockhash
txn = Transaction.new_signed_with_payer(
[st.authorize(
st.AuthorizeParams(
stake=stake,
clock_sysvar=CLOCK,
authority=authority.pubkey(),
new_authority=new_authority,
stake_authorize=stake_authorize,
)
)
)],
payer=payer.pubkey(),
signing_keypairs=signers,
recent_blockhash=recent_blockhash,
)
signers = [payer, authority] if payer.pubkey() != authority.pubkey() else [payer]
recent_blockhash = (await client.get_latest_blockhash()).value.blockhash
await client.send_transaction(txn, *signers, recent_blockhash=recent_blockhash, opts=OPTS)
await client.send_transaction(txn, opts=OPTS)
Loading

0 comments on commit 80ee575

Please sign in to comment.