-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
stake-pool-py: Create and deserialize stake pools (#2557)
* stake-pool-py: Create and deserialize stake pools with CI * Add ability to add / remove validators * Add vote init instruction for cleaner tests * Fixup CI * Add deposit / withdraw sol * Add update instructions * Add increase / decrease stake * Add deposit / withdraw stake
- Loading branch information
Showing
49 changed files
with
2,963 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -ex | ||
cd "$(dirname "$0")/.." | ||
source ./ci/solana-version.sh install | ||
|
||
cd stake-pool/py | ||
python3 -m venv venv | ||
source ./venv/bin/activate | ||
pip3 install -r requirements.txt | ||
check_dirs=( | ||
"spl_token" | ||
"stake" | ||
"stake_pool" | ||
"system" | ||
"tests" | ||
"vote" | ||
) | ||
flake8 "${check_dirs[@]}" | ||
mypy "${check_dirs[@]}" | ||
python3 -m pytest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[flake8] | ||
max-line-length=120 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# python cache files | ||
*__pycache__* | ||
.pytest_cache | ||
.mypy_cache | ||
|
||
# venv | ||
venv/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Stake-Pool Python Bindings | ||
|
||
WIP Python bindings to interact with the stake pool program. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
anyio==3.3.4 | ||
attrs==21.2.0 | ||
base58==2.1.0 | ||
cachetools==4.2.4 | ||
certifi==2021.10.8 | ||
cffi==1.15.0 | ||
charset-normalizer==2.0.7 | ||
construct==2.10.67 | ||
flake8==4.0.1 | ||
h11==0.12.0 | ||
httpcore==0.13.7 | ||
httpx==0.20.0 | ||
idna==3.3 | ||
iniconfig==1.1.1 | ||
mccabe==0.6.1 | ||
mypy==0.910 | ||
mypy-extensions==0.4.3 | ||
packaging==21.2 | ||
pluggy==1.0.0 | ||
py==1.10.0 | ||
pycodestyle==2.8.0 | ||
pycparser==2.20 | ||
pyflakes==2.4.0 | ||
PyNaCl==1.4.0 | ||
pyparsing==2.4.7 | ||
pytest==6.2.5 | ||
pytest-asyncio==0.16.0 | ||
requests==2.26.0 | ||
rfc3986==1.5.0 | ||
six==1.16.0 | ||
sniffio==1.2.0 | ||
solana==0.18.1 | ||
toml==0.10.2 | ||
typing-extensions==3.10.0.2 | ||
urllib3==1.26.7 |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
from solana.publickey import PublicKey | ||
from solana.keypair import Keypair | ||
from solana.rpc.async_api import AsyncClient | ||
from solana.rpc.commitment import Confirmed | ||
from solana.rpc.types import TxOpts | ||
from solana.transaction import Transaction | ||
import solana.system_program as sys | ||
|
||
from spl.token.constants import TOKEN_PROGRAM_ID | ||
from spl.token.async_client import AsyncToken | ||
from spl.token._layouts import MINT_LAYOUT | ||
import spl.token.instructions as spl_token | ||
|
||
|
||
async def create_associated_token_account( | ||
client: AsyncClient, | ||
payer: Keypair, | ||
owner: PublicKey, | ||
mint: PublicKey | ||
) -> PublicKey: | ||
txn = Transaction() | ||
create_txn = spl_token.create_associated_token_account( | ||
payer=payer.public_key, owner=owner, mint=mint | ||
) | ||
txn.add(create_txn) | ||
await client.send_transaction(txn, payer, opts=TxOpts(skip_confirmation=False, preflight_commitment=Confirmed)) | ||
return create_txn.keys[1].pubkey | ||
|
||
|
||
async def create_mint(client: AsyncClient, payer: Keypair, mint: Keypair, mint_authority: PublicKey): | ||
mint_balance = await AsyncToken.get_min_balance_rent_for_exempt_for_mint(client) | ||
print(f"Creating pool token mint {mint.public_key}") | ||
txn = Transaction() | ||
txn.add( | ||
sys.create_account( | ||
sys.CreateAccountParams( | ||
from_pubkey=payer.public_key, | ||
new_account_pubkey=mint.public_key, | ||
lamports=mint_balance, | ||
space=MINT_LAYOUT.sizeof(), | ||
program_id=TOKEN_PROGRAM_ID, | ||
) | ||
) | ||
) | ||
txn.add( | ||
spl_token.initialize_mint( | ||
spl_token.InitializeMintParams( | ||
program_id=TOKEN_PROGRAM_ID, | ||
mint=mint.public_key, | ||
decimals=9, | ||
mint_authority=mint_authority, | ||
freeze_authority=None, | ||
) | ||
) | ||
) | ||
await client.send_transaction( | ||
txn, payer, mint, opts=TxOpts(skip_confirmation=False, preflight_commitment=Confirmed)) |
Empty file.
Oops, something went wrong.