123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062 |
- # seahorse.prelude: the basis for writing Seahorse programs.
- #
- # NOTE: this file just contains types and documentation for your editor. This
- # is NOT executable code, and you won't be able to change the behavior of your
- # Seahorse programs by editing this file.
- from typing import *
- from math import floor, ceil
- T = TypeVar('T')
- N = TypeVar('N')
- # ==========
- # Rust types
- # ==========
- class u8:
- """8-bit unsigned integer."""
- def __init__(self, _: Any) -> 'u8':
- """Construct an u8."""
- def __add__(self, other: 'u8') -> 'u8':
- pass
- def __radd__(self, other: 'u8') -> 'u8':
- pass
- def __iadd__(self, other: 'u8') -> 'u8':
- pass
- def __sub__(self, other: 'u8') -> 'u8':
- pass
- def __rsub__(self, other: 'u8') -> 'u8':
- pass
- def __isub__(self, other: 'u8') -> 'u8':
- pass
- def __mul__(self, other: 'u8') -> 'u8':
- pass
- def __rmul__(self, other: 'u8') -> 'u8':
- pass
- def __imul__(self, other: 'u8') -> 'u8':
- pass
- def __truediv__(self, other: 'f64') -> 'f64':
- pass
- def __rtruediv__(self, other: 'f64') -> 'f64':
- pass
- def __itruediv__(self, other: 'f64') -> 'f64':
- pass
- def __floordiv__(self, other: 'u8') -> 'u8':
- pass
- def __rfloordiv__(self, other: 'u8') -> 'u8':
- pass
- def __ifloordiv__(self, other: 'u8') -> 'u8':
- pass
- def __lt__(self, other: 'u8') -> bool:
- pass
- def __le__(self, other: 'u8') -> bool:
- pass
- def __eq__(self, other: 'u8') -> bool:
- pass
- def __ne__(self, other: 'u8') -> bool:
- pass
- def __ge__(self, other: 'u8') -> bool:
- pass
- def __gt__(self, other: 'u8') -> bool:
- pass
- class u16:
- """16-bit unsigned integer."""
- def __init__(self, _: Any) -> 'u16':
- """Construct an u16."""
- def __add__(self, other: 'u16') -> 'u16':
- pass
- def __radd__(self, other: 'u16') -> 'u16':
- pass
- def __iadd__(self, other: 'u16') -> 'u16':
- pass
- def __sub__(self, other: 'u16') -> 'u16':
- pass
- def __rsub__(self, other: 'u16') -> 'u16':
- pass
- def __isub__(self, other: 'u16') -> 'u16':
- pass
- def __mul__(self, other: 'u16') -> 'u16':
- pass
- def __rmul__(self, other: 'u16') -> 'u16':
- pass
- def __imul__(self, other: 'u16') -> 'u16':
- pass
- def __truediv__(self, other: 'f64') -> 'f64':
- pass
- def __rtruediv__(self, other: 'f64') -> 'f64':
- pass
- def __itruediv__(self, other: 'f64') -> 'f64':
- pass
- def __floordiv__(self, other: 'u16') -> 'u16':
- pass
- def __rfloordiv__(self, other: 'u16') -> 'u16':
- pass
- def __ifloordiv__(self, other: 'u16') -> 'u16':
- pass
- def __lt__(self, other: 'u16') -> bool:
- pass
- def __le__(self, other: 'u16') -> bool:
- pass
- def __eq__(self, other: 'u16') -> bool:
- pass
- def __ne__(self, other: 'u16') -> bool:
- pass
- def __ge__(self, other: 'u16') -> bool:
- pass
- def __gt__(self, other: 'u16') -> bool:
- pass
- class u32:
- """32-bit unsigned integer."""
- def __init__(self, _: Any) -> 'u32':
- """Construct an u32."""
- def __add__(self, other: 'u32') -> 'u32':
- pass
- def __radd__(self, other: 'u32') -> 'u32':
- pass
- def __iadd__(self, other: 'u32') -> 'u32':
- pass
- def __sub__(self, other: 'u32') -> 'u32':
- pass
- def __rsub__(self, other: 'u32') -> 'u32':
- pass
- def __isub__(self, other: 'u32') -> 'u32':
- pass
- def __mul__(self, other: 'u32') -> 'u32':
- pass
- def __rmul__(self, other: 'u32') -> 'u32':
- pass
- def __imul__(self, other: 'u32') -> 'u32':
- pass
- def __truediv__(self, other: 'f64') -> 'f64':
- pass
- def __rtruediv__(self, other: 'f64') -> 'f64':
- pass
- def __itruediv__(self, other: 'f64') -> 'f64':
- pass
- def __floordiv__(self, other: 'u32') -> 'u32':
- pass
- def __rfloordiv__(self, other: 'u32') -> 'u32':
- pass
- def __ifloordiv__(self, other: 'u32') -> 'u32':
- pass
- def __lt__(self, other: 'u32') -> bool:
- pass
- def __le__(self, other: 'u32') -> bool:
- pass
- def __eq__(self, other: 'u32') -> bool:
- pass
- def __ne__(self, other: 'u32') -> bool:
- pass
- def __ge__(self, other: 'u32') -> bool:
- pass
- def __gt__(self, other: 'u32') -> bool:
- pass
- class u64:
- """64-bit unsigned integer."""
- def __init__(self, _: Any) -> 'u64':
- """Construct an u64."""
- def __add__(self, other: 'u64') -> 'u64':
- pass
- def __radd__(self, other: 'u64') -> 'u64':
- pass
- def __iadd__(self, other: 'u64') -> 'u64':
- pass
- def __sub__(self, other: 'u64') -> 'u64':
- pass
- def __rsub__(self, other: 'u64') -> 'u64':
- pass
- def __isub__(self, other: 'u64') -> 'u64':
- pass
- def __mul__(self, other: 'u64') -> 'u64':
- pass
- def __rmul__(self, other: 'u64') -> 'u64':
- pass
- def __imul__(self, other: 'u64') -> 'u64':
- pass
- def __truediv__(self, other: 'f64') -> 'f64':
- pass
- def __rtruediv__(self, other: 'f64') -> 'f64':
- pass
- def __itruediv__(self, other: 'f64') -> 'f64':
- pass
- def __floordiv__(self, other: 'u64') -> 'u64':
- pass
- def __rfloordiv__(self, other: 'u64') -> 'u64':
- pass
- def __ifloordiv__(self, other: 'u64') -> 'u64':
- pass
- def __lt__(self, other: 'u64') -> bool:
- pass
- def __le__(self, other: 'u64') -> bool:
- pass
- def __eq__(self, other: 'u64') -> bool:
- pass
- def __ne__(self, other: 'u64') -> bool:
- pass
- def __ge__(self, other: 'u64') -> bool:
- pass
- def __gt__(self, other: 'u64') -> bool:
- pass
- class u128:
- """128-bit unsigned integer."""
- def __init__(self, _: Any) -> 'u128':
- """Construct an u128."""
- def __add__(self, other: 'u128') -> 'u128':
- pass
- def __radd__(self, other: 'u128') -> 'u128':
- pass
- def __iadd__(self, other: 'u128') -> 'u128':
- pass
- def __sub__(self, other: 'u128') -> 'u128':
- pass
- def __rsub__(self, other: 'u128') -> 'u128':
- pass
- def __isub__(self, other: 'u128') -> 'u128':
- pass
- def __mul__(self, other: 'u128') -> 'u128':
- pass
- def __rmul__(self, other: 'u128') -> 'u128':
- pass
- def __imul__(self, other: 'u128') -> 'u128':
- pass
- def __truediv__(self, other: 'f64') -> 'f64':
- pass
- def __rtruediv__(self, other: 'f64') -> 'f64':
- pass
- def __itruediv__(self, other: 'f64') -> 'f64':
- pass
- def __floordiv__(self, other: 'u128') -> 'u128':
- pass
- def __rfloordiv__(self, other: 'u128') -> 'u128':
- pass
- def __ifloordiv__(self, other: 'u128') -> 'u128':
- pass
- def __lt__(self, other: 'u128') -> bool:
- pass
- def __le__(self, other: 'u128') -> bool:
- pass
- def __eq__(self, other: 'u128') -> bool:
- pass
- def __ne__(self, other: 'u128') -> bool:
- pass
- def __ge__(self, other: 'u128') -> bool:
- pass
- def __gt__(self, other: 'u128') -> bool:
- pass
- class i8:
- """8-bit signed integer."""
- def __init__(self, _: Any) -> 'i8':
- """Construct an i8."""
- def __add__(self, other: 'i8') -> 'i8':
- pass
- def __radd__(self, other: 'i8') -> 'i8':
- pass
- def __iadd__(self, other: 'i8') -> 'i8':
- pass
- def __sub__(self, other: 'i8') -> 'i8':
- pass
- def __rsub__(self, other: 'i8') -> 'i8':
- pass
- def __isub__(self, other: 'i8') -> 'i8':
- pass
- def __mul__(self, other: 'i8') -> 'i8':
- pass
- def __rmul__(self, other: 'i8') -> 'i8':
- pass
- def __imul__(self, other: 'i8') -> 'i8':
- pass
- def __truediv__(self, other: 'f64') -> 'f64':
- pass
- def __rtruediv__(self, other: 'f64') -> 'f64':
- pass
- def __itruediv__(self, other: 'f64') -> 'f64':
- pass
- def __floordiv__(self, other: 'i8') -> 'i8':
- pass
- def __rfloordiv__(self, other: 'i8') -> 'i8':
- pass
- def __ifloordiv__(self, other: 'i8') -> 'i8':
- pass
- class i16:
- """16-bit signed integer."""
- def __init__(self, _: Any) -> 'i16':
- """Construct an i16."""
- def __add__(self, other: 'i16') -> 'i16':
- pass
- def __radd__(self, other: 'i16') -> 'i16':
- pass
- def __iadd__(self, other: 'i16') -> 'i16':
- pass
- def __sub__(self, other: 'i16') -> 'i16':
- pass
- def __rsub__(self, other: 'i16') -> 'i16':
- pass
- def __isub__(self, other: 'i16') -> 'i16':
- pass
- def __mul__(self, other: 'i16') -> 'i16':
- pass
- def __rmul__(self, other: 'i16') -> 'i16':
- pass
- def __imul__(self, other: 'i16') -> 'i16':
- pass
- def __truediv__(self, other: 'f64') -> 'f64':
- pass
- def __rtruediv__(self, other: 'f64') -> 'f64':
- pass
- def __itruediv__(self, other: 'f64') -> 'f64':
- pass
- def __floordiv__(self, other: 'i16') -> 'i16':
- pass
- def __rfloordiv__(self, other: 'i16') -> 'i16':
- pass
- def __ifloordiv__(self, other: 'i16') -> 'i16':
- pass
- def __lt__(self, other: 'i16') -> bool:
- pass
- def __le__(self, other: 'i16') -> bool:
- pass
- def __eq__(self, other: 'i16') -> bool:
- pass
- def __ne__(self, other: 'i16') -> bool:
- pass
- def __ge__(self, other: 'i16') -> bool:
- pass
- def __gt__(self, other: 'i16') -> bool:
- pass
- class i32:
- """32-bit signed integer."""
- def __init__(self, _: Any) -> 'i32':
- """Construct an i32."""
- def __add__(self, other: 'i32') -> 'i32':
- pass
- def __radd__(self, other: 'i32') -> 'i32':
- pass
- def __iadd__(self, other: 'i32') -> 'i32':
- pass
- def __sub__(self, other: 'i32') -> 'i32':
- pass
- def __rsub__(self, other: 'i32') -> 'i32':
- pass
- def __isub__(self, other: 'i32') -> 'i32':
- pass
- def __mul__(self, other: 'i32') -> 'i32':
- pass
- def __rmul__(self, other: 'i32') -> 'i32':
- pass
- def __imul__(self, other: 'i32') -> 'i32':
- pass
- def __truediv__(self, other: 'f64') -> 'f64':
- pass
- def __rtruediv__(self, other: 'f64') -> 'f64':
- pass
- def __itruediv__(self, other: 'f64') -> 'f64':
- pass
- def __floordiv__(self, other: 'i32') -> 'i32':
- pass
- def __rfloordiv__(self, other: 'i32') -> 'i32':
- pass
- def __ifloordiv__(self, other: 'i32') -> 'i32':
- pass
- def __lt__(self, other: 'i32') -> bool:
- pass
- def __le__(self, other: 'i32') -> bool:
- pass
- def __eq__(self, other: 'i32') -> bool:
- pass
- def __ne__(self, other: 'i32') -> bool:
- pass
- def __ge__(self, other: 'i32') -> bool:
- pass
- def __gt__(self, other: 'i32') -> bool:
- pass
- class i64:
- """64-bit signed integer."""
- def __init__(self, _: Any) -> 'i64':
- """Construct an i64."""
- def __add__(self, other: 'i64') -> 'i64':
- pass
- def __radd__(self, other: 'i64') -> 'i64':
- pass
- def __iadd__(self, other: 'i64') -> 'i64':
- pass
- def __sub__(self, other: 'i64') -> 'i64':
- pass
- def __rsub__(self, other: 'i64') -> 'i64':
- pass
- def __isub__(self, other: 'i64') -> 'i64':
- pass
- def __mul__(self, other: 'i64') -> 'i64':
- pass
- def __rmul__(self, other: 'i64') -> 'i64':
- pass
- def __imul__(self, other: 'i64') -> 'i64':
- pass
- def __truediv__(self, other: 'f64') -> 'f64':
- pass
- def __rtruediv__(self, other: 'f64') -> 'f64':
- pass
- def __itruediv__(self, other: 'f64') -> 'f64':
- pass
- def __floordiv__(self, other: 'i64') -> 'i64':
- pass
- def __rfloordiv__(self, other: 'i64') -> 'i64':
- pass
- def __ifloordiv__(self, other: 'i64') -> 'i64':
- pass
- def __lt__(self, other: 'i64') -> bool:
- pass
- def __le__(self, other: 'i64') -> bool:
- pass
- def __eq__(self, other: 'i64') -> bool:
- pass
- def __ne__(self, other: 'i64') -> bool:
- pass
- def __ge__(self, other: 'i64') -> bool:
- pass
- def __gt__(self, other: 'i64') -> bool:
- pass
- class i128:
- """128-bit signed integer."""
- def __init__(self, _: Any) -> 'i128':
- """Construct an i128."""
- def __add__(self, other: 'i128') -> 'i128':
- pass
- def __radd__(self, other: 'i128') -> 'i128':
- pass
- def __iadd__(self, other: 'i128') -> 'i128':
- pass
- def __sub__(self, other: 'i128') -> 'i128':
- pass
- def __rsub__(self, other: 'i128') -> 'i128':
- pass
- def __isub__(self, other: 'i128') -> 'i128':
- pass
- def __mul__(self, other: 'i128') -> 'i128':
- pass
- def __rmul__(self, other: 'i128') -> 'i128':
- pass
- def __imul__(self, other: 'i128') -> 'i128':
- pass
- def __truediv__(self, other: 'f64') -> 'f64':
- pass
- def __rtruediv__(self, other: 'f64') -> 'f64':
- pass
- def __itruediv__(self, other: 'f64') -> 'f64':
- pass
- def __floordiv__(self, other: 'i128') -> 'i128':
- pass
- def __rfloordiv__(self, other: 'i128') -> 'i128':
- pass
- def __ifloordiv__(self, other: 'i128') -> 'i128':
- pass
- def __lt__(self, other: 'i128') -> bool:
- pass
- def __le__(self, other: 'i128') -> bool:
- pass
- def __eq__(self, other: 'i128') -> bool:
- pass
- def __ne__(self, other: 'i128') -> bool:
- pass
- def __ge__(self, other: 'i128') -> bool:
- pass
- def __gt__(self, other: 'i128') -> bool:
- pass
- class f64:
- """64-bit floating point number."""
- def __init__(self, _: Any) -> 'f64':
- """Construct an f64."""
- def __add__(self, other: 'f64') -> 'f64':
- pass
- def __radd__(self, other: 'f64') -> 'f64':
- pass
- def __iadd__(self, other: 'f64') -> 'f64':
- pass
- def __sub__(self, other: 'f64') -> 'f64':
- pass
- def __rsub__(self, other: 'f64') -> 'f64':
- pass
- def __isub__(self, other: 'f64') -> 'f64':
- pass
- def __mul__(self, other: 'f64') -> 'f64':
- pass
- def __rmul__(self, other: 'f64') -> 'f64':
- pass
- def __imul__(self, other: 'f64') -> 'f64':
- pass
- def __truediv__(self, other: 'f64') -> 'f64':
- pass
- def __rtruediv__(self, other: 'f64') -> 'f64':
- pass
- def __itruediv__(self, other: 'f64') -> 'f64':
- pass
- def __floordiv__(self, other: 'f64') -> 'f64':
- pass
- def __rfloordiv__(self, other: 'f64') -> 'f64':
- pass
- def __ifloordiv__(self, other: 'f64') -> 'f64':
- pass
- def __lt__(self, other: 'f64') -> bool:
- pass
- def __le__(self, other: 'f64') -> bool:
- pass
- def __eq__(self, other: 'f64') -> bool:
- pass
- def __ne__(self, other: 'f64') -> bool:
- pass
- def __ge__(self, other: 'f64') -> bool:
- pass
- def __gt__(self, other: 'f64') -> bool:
- pass
- class Array(Generic[T, N]):
- """
- A fixed-length array: contains type T and has size N.
- N must be known at compile-time, and may not be anything other than a non-negative integer literal. Example:
- ```
- # Good
- a: Array[u8, 4]
- # Bad
- N = 4
- a: Array[u8, N]
- ```
- """
- def __init__(iterable: Iterable[T], len: N) -> 'Array[T, N]':
- """
- Construct an array from an iterable and a length.
- The parameter len must be known at compile-time, and may not be anything other than a non-negative integer literal. Example:
- ```
- a = [0, 1, 2, 3]
- # Good
- Array(a, 4)
- # Compiles, but will definitely error at runtime
- Array(a, 5)
- # Bad (will not compile)
- a = [0, 1, 2, 3]
- Array(a, len(a))
- ```
- """
- def __getitem__(self, index: Any) -> T:
- """
- Index into this array.
-
- Like Python's native list type, performs wrapping indexing - if you pass in -1, you'll get the last element of the array.
- """
- def array(*elements: T) -> Array[T, N]:
- """
- Create an array from a variadic list of elements. Example:
- ```
- # Array[u64, 3]
- array(u64(0), 1, 2)
- # Array[str, 4]
- array('seahorse', 'is', 'the', 'best!')
- ```
- """
- class Enum:
- """
- A type that can have one of multiple named values.
- Note that unlike Rust enums, these cannot contain any data (other than the variant itself). Example:
- ```
- class MyEnum(Enum):
- ONE = 1
- TWO = 2
- THREE = 3
- @instruction
- def use_enum(code: MyEnum):
- if code == MyEnum.ONE:
- print(1)
- # ...
- ```
- """
- # ============
- # Solana types
- # ============
- class Pubkey:
- """32-byte account identifier."""
- def find_program_address(seeds: List[Any], program_id: 'Pubkey' = None) -> Tuple['Pubkey', u8]:
- """
- Find a valid program derived address and its corresponding bump seed. Calls the same function from Solana's Pubkey struct - read more [here](https://docs.rs/solana-program/latest/solana_program/pubkey/struct.Pubkey.html#method.find_program_address).
-
- @param seeds: A list of parameters to uniquely identify this account among all accounts created by your program. These may be string literals, other accounts, integers, or lists of bytes.
- @param program_id: The pubkey of the program that the PDA belongs to. Defaults to the current program's key.
- @returns: The canonical pubkey and bump seed.
- """
- class AccountWithKey:
- """Generic Solana account."""
- def key(self) -> Pubkey:
- """Get this account's key."""
- class Account(AccountWithKey):
- """User-defined Solana account."""
- def transfer_lamports(self, to: AccountWithKey, amount: u64):
- """
- Transfer some SOL directly to another account. Since this account is program-owned, this transfer does not require a CPI.
- @param to: The recipient Solana account.
- @param amount: The amount (in lamports, not SOL) to transfer.
- """
- class Event:
- """Anchor event that clients can listen for"""
- def emit(self):
- """
- Emit the event to the blockchain
- """
- class Signer(AccountWithKey):
- """Instruction signer."""
- def transfer_lamports(self, to: AccountWithKey, amount: u64):
- """
- Transfer some SOL directly to another account. Unlike using transfer_lamports from a program account, this transfer will require a CPI.
- @param to: The recipient Solana account.
- @param amount: The amount (in lamports, not SOL) to transfer.
- """
- class Empty(Generic[T]):
- """An account that needs to be initialized."""
- def init(self, payer: Signer, seeds: List[Any] = None, mint: 'TokenMint' = None, decimals: u8 = None, authority: AccountWithKey = None, associated: bool = False, space: u64 = None, padding: u64 = None) -> T:
- """
- Initialize the account.
-
- @param payer: The account that will pay for the rent cost of the initialized account. Must be an instruction signer.
- @param seeds: A list of parameters to uniquely identify this account among all accounts created by your program. These may be string literals, other accounts, integers, or lists of bytes.
- @param mint: If initializing a TokenAccount, this is the mint that the account belongs to.
- @param decimals: If initializing a TokenMint, this is the number of decimals the new token has.
- @param authority: If initializing a TokenAccount/TokenMint, this is the account that has authority over the account.
- @param associated: If initializing an associated token account, must be set to true.
- @param space: If initializing a program account, you can use this to overwrite Seahorse's calculation of the account size.
- @param padding: If initializing a program account, you can use this to add extra space to Seahorse's calculation of the account size.
- @returns: The new, initialized account. All of the data in this account will be set to 0, bytewise.
- """
- def bump(self) -> u8:
- """
- Get this account's bump, needed if you want to use this account to sign CPI calls.
-
- If you've initialized an account without seeds, then a bump will not have been calculated. This will result in a runtime error when you try to access it.
- """
- def key(self) -> Pubkey:
- """Get this account's key."""
- class CpiAccount:
- """Account and metadata used for making arbitrary CPIs (via `Program.invoke`)."""
- def __init__(account: AccountWithKey, mut: bool = False, signer: bool = False, seeds: List[Any] = None) -> 'CpiAccount':
- """
- Create the CpiAccount.
- @param account: The account being passed to the CPI.
- @param mut: Whether this account needs to be mutable for the CPI - defaults to false.
- @param signer: Whether this account needs to be an instruction signer - defaults to false. Mutually exclusive with seeds, and should only really be true if account is a Signer.
- @param seeds: PDA signer seeds, if this account needs to sign the CPI. Mutually exclusive with signer.
- """
- class Program(AccountWithKey):
- """Arbitrary program."""
- def invoke(self, accounts: List[CpiAccount], data: List[u8]):
- """
- Call this program in a cross-program invocation. Make sure you know what you're doing before you try using this - a poorly crafted data list could cost you real money.
- @param accounts: List of accounts being passed to the CPI - the program itself does not need to be in here.
- @param data: "Raw" list of bytes used to tell the program what to do, pass args, etc.
- """
- class UncheckedAccount(AccountWithKey):
- """
- Raw account that has had no safety checks performed on it.
-
- The underlying Anchor code cannot guarantee anything about the account unless you check it in your instruction - not the type, not the data, not the program it came from. Use carefully.
- """
- class Clock:
- """
- Solana's Clock sysvar.
-
- Consult Solana's reference to learn more. Information copied from https://docs.rs/solana-program/1.14.3/solana_program/clock/struct.Clock.html.
- """
- def slot(self) -> u64:
- """Get the current network/bank Slot."""
- def epoch_start_timestamp(self) -> i64:
- """Get the timestamp of the first Slot in this Epoch."""
- def epoch(self) -> u64:
- """Get the bank Epoch."""
- def leader_schedule_epoch(self) -> u64:
- """Get the future Epoch for which the leader schedule has most recently been calculated."""
- def unix_timestamp(self) -> i64:
- """
- Get the estimated current UNIX timestamp.
-
- Originally computed from genesis creation time and network time in slots (drifty); corrected using validator timestamp oracle as of timestamp_correction and timestamp_bounding features.
- """
- class TokenAccount(AccountWithKey):
- """SPL token account."""
- def authority(self) -> Pubkey:
- """Get the owner of this token account."""
- def amount(self) -> u64:
- """Get the amount of token stored in this account."""
- def mint(self) -> Pubkey:
- """Get the mint that this token account corresponds to."""
- def transfer(self, authority: AccountWithKey, to: 'TokenAccount', amount: u64, signer: List[Any] = None):
- """
- Transfer funds from this SPL token account to another.
-
- @param authority: The account that owns this TokenAccount. Must be an instruction signer or the account given by the `signer` param.
- @param to: The recipient TokenAccount.
- @param amount: How much (in *native* token units) to transfer.
- @param signer: (Optional) seeds for the signature of a PDA.
- """
- class TokenMint(AccountWithKey):
- """SPL token mint."""
- def authority(self) -> Pubkey:
- """Get the owner of this token mint."""
- def freeze_authority(self) -> Pubkey:
- """Get the freeze authority of this token mint."""
- def decimals(self) -> u8:
- """Get the number of decimals for this token."""
- def supply(self) -> u64:
- """Get the amount of this token that exists."""
- def mint(self, authority: AccountWithKey, to: TokenAccount, amount: u64, signer: List[Any] = None):
- """
- Mint new tokens to a token account.
- @param authority: The account that owns this TokenMint. Must be an instruction signer or the account given by the `signer` param.
- @param to: The recipient TokenAccount.
- @param amount: How much (in *native* token units) to mint.
- @param signer: (Optional) seeds for the signature of a PDA.
- """
- def burn(self, authority: AccountWithKey, holder: TokenAccount, amount: u64, signer: List[Any] = None):
- """
- Burn tokens from a token account.
- @param authority: The account that owns the `holder` TokenAccount. Must be an instruction signer or the account given by the `signer` param.
- @param holder: The TokenAccount to burn from.
- @param amount: How much (in *native* token units) to burn.
- @param signer: (Optional) seeds for the signature of a PDA.
- """
- # ================
- # Helper functions
- # ================
- def declare_id(id: str):
- """Inform Anchor what this program's ID is.
- @param id: The program's ID, generated by Anchor in /target/idl/<program>.json. This must be copied-pasted straight from there as a string literal.
- """
- def instruction(function: Callable[..., None]) -> Callable[..., None]:
- """Decorator to turn a function into a program instruction."""
- def dataclass(function: Callable[..., None]) -> Callable[..., None]:
- """Decorator to create an automatic default class constructor."""
- def int_bytes(n: Any, be: bool = False) -> List[u8]:
- """
- Convenience method to turn an integer type into a little-endian (by default) list of bytes.
-
- @param n: The integer you wish to convert to bytes.
- @param be: Whether you want the conversion to be big-endian - defaults to false.
- """
- def size(ob: str) -> u64:
- """
- Get the size of an object in bytes.
- Currently this is only supported for strings.
-
- @param ob: The object to get the size of.
- """
|