Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Commit a788886

Browse files
authored
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
1 parent e29bc53 commit a788886

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+2963
-30
lines changed

.github/workflows/fuzz-nightly.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ jobs:
4444

4545
- uses: actions/cache@v2
4646
with:
47-
path: |
48-
~/.cache
47+
path: ~/.cache/solana
4948
key: solana-${{ env.SOLANA_VERSION }}
5049
restore-keys: |
5150
solana-

.github/workflows/pull-request-binary-oracle-pair.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ jobs:
4545

4646
- uses: actions/cache@v2
4747
with:
48-
path: |
49-
~/.cache
48+
path: ~/.cache/solana
5049
key: solana-${{ env.SOLANA_VERSION }}
5150

5251
- name: Install dependencies

.github/workflows/pull-request-examples.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ jobs:
4343

4444
- uses: actions/cache@v2
4545
with:
46-
path: |
47-
~/.cache
46+
path: ~/.cache/solana
4847
key: solana-${{ env.SOLANA_VERSION }}
4948

5049
- name: Install dependencies

.github/workflows/pull-request-feature-proposal.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ jobs:
4545

4646
- uses: actions/cache@v2
4747
with:
48-
path: |
49-
~/.cache
48+
path: ~/.cache/solana
5049
key: solana-${{ env.SOLANA_VERSION }}
5150

5251
- name: Install dependencies

.github/workflows/pull-request-governance.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ jobs:
4545

4646
- uses: actions/cache@v2
4747
with:
48-
path: |
49-
~/.cache
48+
path: ~/.cache/solana
5049
key: solana-${{ env.SOLANA_VERSION }}
5150

5251
- name: Install dependencies

.github/workflows/pull-request-libraries.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ jobs:
4343

4444
- uses: actions/cache@v2
4545
with:
46-
path: |
47-
~/.cache
46+
path: ~/.cache/solana
4847
key: solana-${{ env.SOLANA_VERSION }}
4948

5049
- name: Install dependencies

.github/workflows/pull-request-memo.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ jobs:
4343

4444
- uses: actions/cache@v2
4545
with:
46-
path: |
47-
~/.cache
46+
path: ~/.cache/solana
4847
key: solana-${{ env.SOLANA_VERSION }}
4948

5049
- name: Install dependencies

.github/workflows/pull-request-name-service.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ jobs:
4343

4444
- uses: actions/cache@v2
4545
with:
46-
path: |
47-
~/.cache
46+
path: ~/.cache/solana
4847
key: solana-${{ env.SOLANA_VERSION }}
4948

5049
- name: Install dependencies

.github/workflows/pull-request-record.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ jobs:
4343

4444
- uses: actions/cache@v2
4545
with:
46-
path: |
47-
~/.cache
46+
path: ~/.cache/solana
4847
key: solana-${{ env.SOLANA_VERSION }}
4948

5049
- name: Install dependencies

.github/workflows/pull-request-shared-memory.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ jobs:
4343

4444
- uses: actions/cache@v2
4545
with:
46-
path: |
47-
~/.cache
46+
path: ~/.cache/solana
4847
key: solana-${{ env.SOLANA_VERSION }}
4948

5049
- name: Install dependencies

.github/workflows/pull-request-stake-pool.yml

+32-2
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ jobs:
4545

4646
- uses: actions/cache@v2
4747
with:
48-
path: |
49-
~/.cache
48+
path: ~/.cache/solana
5049
key: solana-${{ env.SOLANA_VERSION }}
5150

5251
- name: Install dependencies
@@ -57,3 +56,34 @@ jobs:
5756
5857
- name: Build and test
5958
run: ./ci/cargo-test-bpf.sh stake-pool
59+
60+
- name: Upload programs
61+
uses: actions/upload-artifact@v2
62+
with:
63+
name: stake-pool-programs
64+
path: "target/deploy/*.so"
65+
if-no-files-found: error
66+
67+
py-test:
68+
runs-on: ubuntu-latest
69+
needs: cargo-test-bpf
70+
steps:
71+
- uses: actions/checkout@v2
72+
73+
- name: Setup Python version
74+
uses: actions/setup-python@v2
75+
with:
76+
python-version: 3.8
77+
78+
- uses: actions/cache@v2
79+
with:
80+
path: ~/.cache/pip
81+
key: pip-stake-pool-${{ hashFiles('stake-pool/py/requirements.txt') }}
82+
83+
- name: Download programs
84+
uses: actions/download-artifact@v2
85+
with:
86+
name: stake-pool-programs
87+
path: target/deploy
88+
89+
- run: ./ci/py-test-stake-pool.sh

.github/workflows/pull-request-token-lending.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ jobs:
4545

4646
- uses: actions/cache@v2
4747
with:
48-
path: |
49-
~/.cache
48+
path: ~/.cache/solana
5049
key: solana-${{ env.SOLANA_VERSION }}
5150

5251
- name: Install dependencies

.github/workflows/pull-request-token-swap.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ jobs:
4747

4848
- uses: actions/cache@v2
4949
with:
50-
path: |
51-
~/.cache
50+
path: ~/.cache/solana
5251
key: solana-${{ env.SOLANA_VERSION }}
5352

5453
- name: Install dependencies

.github/workflows/pull-request-token.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ jobs:
4545

4646
- uses: actions/cache@v2
4747
with:
48-
path: |
49-
~/.cache
48+
path: ~/.cache/solana
5049
key: solana-${{ env.SOLANA_VERSION }}
5150

5251
- name: Install dependencies

.github/workflows/pull-request.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,7 @@ jobs:
112112

113113
- uses: actions/cache@v2
114114
with:
115-
path: |
116-
~/.cache
115+
path: ~/.cache/solana
117116
key: solana-${{ env.SOLANA_VERSION }}
118117

119118
- name: Install dependencies

ci/py-test-stake-pool.sh

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env bash
2+
3+
set -ex
4+
cd "$(dirname "$0")/.."
5+
source ./ci/solana-version.sh install
6+
7+
cd stake-pool/py
8+
python3 -m venv venv
9+
source ./venv/bin/activate
10+
pip3 install -r requirements.txt
11+
check_dirs=(
12+
"spl_token"
13+
"stake"
14+
"stake_pool"
15+
"system"
16+
"tests"
17+
"vote"
18+
)
19+
flake8 "${check_dirs[@]}"
20+
mypy "${check_dirs[@]}"
21+
python3 -m pytest

stake-pool/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ Full documentation is available at https://spl.solana.com/stake-pool
55
The command-line interface tool is available in the `./cli` directory.
66

77
Javascript bindings are available in the `./js` directory.
8+
9+
Python bindings are available in the `./py` directory.

stake-pool/py/.flake8

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[flake8]
2+
max-line-length=120

stake-pool/py/.gitignore

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# python cache files
2+
*__pycache__*
3+
.pytest_cache
4+
.mypy_cache
5+
6+
# venv
7+
venv/

stake-pool/py/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Stake-Pool Python Bindings
2+
3+
WIP Python bindings to interact with the stake pool program.

stake-pool/py/requirements.txt

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
anyio==3.3.4
2+
attrs==21.2.0
3+
base58==2.1.0
4+
cachetools==4.2.4
5+
certifi==2021.10.8
6+
cffi==1.15.0
7+
charset-normalizer==2.0.7
8+
construct==2.10.67
9+
flake8==4.0.1
10+
h11==0.12.0
11+
httpcore==0.13.7
12+
httpx==0.20.0
13+
idna==3.3
14+
iniconfig==1.1.1
15+
mccabe==0.6.1
16+
mypy==0.910
17+
mypy-extensions==0.4.3
18+
packaging==21.2
19+
pluggy==1.0.0
20+
py==1.10.0
21+
pycodestyle==2.8.0
22+
pycparser==2.20
23+
pyflakes==2.4.0
24+
PyNaCl==1.4.0
25+
pyparsing==2.4.7
26+
pytest==6.2.5
27+
pytest-asyncio==0.16.0
28+
requests==2.26.0
29+
rfc3986==1.5.0
30+
six==1.16.0
31+
sniffio==1.2.0
32+
solana==0.18.1
33+
toml==0.10.2
34+
typing-extensions==3.10.0.2
35+
urllib3==1.26.7

stake-pool/py/spl_token/__init__.py

Whitespace-only changes.

stake-pool/py/spl_token/actions.py

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
from solana.publickey import PublicKey
2+
from solana.keypair import Keypair
3+
from solana.rpc.async_api import AsyncClient
4+
from solana.rpc.commitment import Confirmed
5+
from solana.rpc.types import TxOpts
6+
from solana.transaction import Transaction
7+
import solana.system_program as sys
8+
9+
from spl.token.constants import TOKEN_PROGRAM_ID
10+
from spl.token.async_client import AsyncToken
11+
from spl.token._layouts import MINT_LAYOUT
12+
import spl.token.instructions as spl_token
13+
14+
15+
async def create_associated_token_account(
16+
client: AsyncClient,
17+
payer: Keypair,
18+
owner: PublicKey,
19+
mint: PublicKey
20+
) -> PublicKey:
21+
txn = Transaction()
22+
create_txn = spl_token.create_associated_token_account(
23+
payer=payer.public_key, owner=owner, mint=mint
24+
)
25+
txn.add(create_txn)
26+
await client.send_transaction(txn, payer, opts=TxOpts(skip_confirmation=False, preflight_commitment=Confirmed))
27+
return create_txn.keys[1].pubkey
28+
29+
30+
async def create_mint(client: AsyncClient, payer: Keypair, mint: Keypair, mint_authority: PublicKey):
31+
mint_balance = await AsyncToken.get_min_balance_rent_for_exempt_for_mint(client)
32+
print(f"Creating pool token mint {mint.public_key}")
33+
txn = Transaction()
34+
txn.add(
35+
sys.create_account(
36+
sys.CreateAccountParams(
37+
from_pubkey=payer.public_key,
38+
new_account_pubkey=mint.public_key,
39+
lamports=mint_balance,
40+
space=MINT_LAYOUT.sizeof(),
41+
program_id=TOKEN_PROGRAM_ID,
42+
)
43+
)
44+
)
45+
txn.add(
46+
spl_token.initialize_mint(
47+
spl_token.InitializeMintParams(
48+
program_id=TOKEN_PROGRAM_ID,
49+
mint=mint.public_key,
50+
decimals=9,
51+
mint_authority=mint_authority,
52+
freeze_authority=None,
53+
)
54+
)
55+
)
56+
await client.send_transaction(
57+
txn, payer, mint, opts=TxOpts(skip_confirmation=False, preflight_commitment=Confirmed))

stake-pool/py/stake/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)