Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add NATIVE_DECIMALS & solana constants #436

Merged
merged 2 commits into from
Jun 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions src/solana/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""Solana constants."""

from solders.pubkey import Pubkey

LAMPORTS_PER_SOL: int = 1_000_000_000
"""Number of lamports per SOL, where 1 SOL equals 1 billion lamports."""

SYSTEM_PROGRAM_ID = Pubkey.from_string("11111111111111111111111111111111")
"""Program ID for the System Program."""

CONFIG_PROGRAM_ID: Pubkey = Pubkey.from_string("Config1111111111111111111111111111111111111")
"""Program ID for the Config Program."""

STAKE_PROGRAM_ID: Pubkey = Pubkey.from_string("Stake11111111111111111111111111111111111111")
"""Program ID for the Stake Program."""

VOTE_PROGRAM_ID: Pubkey = Pubkey.from_string("Vote111111111111111111111111111111111111111")
"""Program ID for the Vote Program."""

ADDRESS_LOOKUP_TABLE_PROGRAM_ID: Pubkey = Pubkey.from_string("AddressLookupTab1e1111111111111111111111111")
"""Program ID for the Address Lookup Table Program."""

BPF_LOADER_PROGRAM_ID: Pubkey = Pubkey.from_string("BPFLoaderUpgradeab1e11111111111111111111111")
"""Program ID for the BPF Loader Program."""

ED25519_PROGRAM_ID: Pubkey = Pubkey.from_string("Ed25519SigVerify111111111111111111111111111")
"""Program ID for the Ed25519 Program."""

SECP256K1_PROGRAM_ID: Pubkey = Pubkey.from_string("KeccakSecp256k11111111111111111111111111111")
"""Program ID for the Secp256k1 Program."""
5 changes: 1 addition & 4 deletions src/solana/vote_program.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,9 @@
from solders.instruction import AccountMeta, Instruction
from solders.pubkey import Pubkey

from solana.constants import VOTE_PROGRAM_ID
from solana._layouts.vote_instructions import VOTE_INSTRUCTIONS_LAYOUT, InstructionType

VOTE_PROGRAM_ID: Pubkey = Pubkey.from_string("Vote111111111111111111111111111111111111111")
"""Public key that identifies the Vote program."""


# Instrection Params
class WithdrawFromVoteAccountParams(NamedTuple):
"""Transfer SOL from vote account to identity."""
Expand Down
3 changes: 3 additions & 0 deletions src/spl/token/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@
other Token program token type and can be useful when being called from other programs that interact
with the Token Program's interface.
"""

NATIVE_DECIMALS: int = 9
"""Number of decimals for SOL and the Wrapped SOL mint."""
5 changes: 2 additions & 3 deletions tests/integration/test_async_http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from solders.transaction import VersionedTransaction
from spl.token.constants import WRAPPED_SOL_MINT

from solana.constants import VOTE_PROGRAM_ID
from solana.rpc.async_api import AsyncClient
from solana.rpc.commitment import Confirmed, Finalized, Processed
from solana.rpc.core import RPCException, TransactionExpiredBlockheightExceededError
Expand Down Expand Up @@ -360,9 +361,7 @@ async def test_get_blocks(test_http_client_async):
@pytest.mark.integration
async def test_get_signatures_for_address(test_http_client_async: AsyncClient):
"""Test get signatures for addresses."""
resp = await test_http_client_async.get_signatures_for_address(
Pubkey.from_string("Vote111111111111111111111111111111111111111"), limit=1, commitment=Confirmed
)
resp = await test_http_client_async.get_signatures_for_address(VOTE_PROGRAM_ID, limit=1, commitment=Confirmed)
assert_valid_response(resp)


Expand Down
7 changes: 3 additions & 4 deletions tests/integration/test_http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@
from solders.rpc.requests import GetBlockHeight, GetFirstAvailableBlock
from solders.rpc.responses import GetBlockHeightResp, GetFirstAvailableBlockResp, Resp
from solders.transaction import VersionedTransaction
from spl.token.constants import WRAPPED_SOL_MINT

from solana.constants import VOTE_PROGRAM_ID
from solana.rpc.api import Client
from solana.rpc.commitment import Confirmed, Finalized, Processed
from solana.rpc.core import RPCException, TransactionExpiredBlockheightExceededError
from solana.rpc.types import DataSliceOpts, TxOpts
from solana.transaction import Transaction
from spl.token.constants import WRAPPED_SOL_MINT

from ..utils import AIRDROP_AMOUNT, assert_valid_response

Expand Down Expand Up @@ -344,9 +345,7 @@ def test_get_blocks(test_http_client: Client):
@pytest.mark.integration
def test_get_signatures_for_address(test_http_client: Client):
"""Test get signatures for addresses."""
resp = test_http_client.get_signatures_for_address(
Pubkey.from_string("Vote111111111111111111111111111111111111111"), limit=1, commitment=Confirmed
)
resp = test_http_client.get_signatures_for_address(VOTE_PROGRAM_ID, limit=1, commitment=Confirmed)
assert_valid_response(resp)


Expand Down
5 changes: 3 additions & 2 deletions tests/unit/test_async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from solders.rpc.requests import GetSignaturesForAddress
from solders.signature import Signature

from solana.constants import SYSTEM_PROGRAM_ID
from solana.exceptions import SolanaRpcException
from solana.rpc.commitment import Finalized

Expand All @@ -26,7 +27,7 @@ async def test_async_client_http_exception(unit_test_http_client_async):
def test_client_address_sig_args_no_commitment(unit_test_http_client_async):
"""Test generating getSignaturesForAddressBody."""
expected = GetSignaturesForAddress(
Pubkey.from_string("11111111111111111111111111111111"),
SYSTEM_PROGRAM_ID,
RpcSignaturesForAddressConfig(
limit=5, before=Signature.default(), until=Signature.default(), commitment=CommitmentLevel.Processed
),
Expand All @@ -39,7 +40,7 @@ def test_client_address_sig_args_no_commitment(unit_test_http_client_async):

def test_client_address_sig_args_with_commitment(unit_test_http_client_async):
expected = GetSignaturesForAddress(
Pubkey.from_string("11111111111111111111111111111111"),
SYSTEM_PROGRAM_ID,
RpcSignaturesForAddressConfig(limit=5, commitment=CommitmentLevel.Finalized),
)
actual = unit_test_http_client_async._get_signatures_for_address_body(
Expand Down
5 changes: 3 additions & 2 deletions tests/unit/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from solders.rpc.requests import GetSignaturesForAddress
from solders.signature import Signature

from solana.constants import SYSTEM_PROGRAM_ID
from solana.exceptions import SolanaRpcException
from solana.rpc.commitment import Finalized

Expand All @@ -26,7 +27,7 @@ def test_client_http_exception(unit_test_http_client):
def test_client_address_sig_args_no_commitment(unit_test_http_client):
"""Test generating getSignaturesForAddress body."""
expected = GetSignaturesForAddress(
Pubkey.from_string("11111111111111111111111111111111"),
SYSTEM_PROGRAM_ID,
RpcSignaturesForAddressConfig(
limit=5, before=Signature.default(), until=Signature.default(), commitment=CommitmentLevel.Processed
),
Expand All @@ -39,7 +40,7 @@ def test_client_address_sig_args_no_commitment(unit_test_http_client):

def test_client_address_sig_args_with_commitment(unit_test_http_client):
expected = GetSignaturesForAddress(
Pubkey.from_string("11111111111111111111111111111111"),
SYSTEM_PROGRAM_ID,
RpcSignaturesForAddressConfig(limit=5, commitment=CommitmentLevel.Finalized),
)
actual = unit_test_http_client._get_signatures_for_address_body(Pubkey([0] * 31 + [0]), None, None, 5, Finalized)
Expand Down
Loading