prelude.py 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062
  1. # seahorse.prelude: the basis for writing Seahorse programs.
  2. #
  3. # NOTE: this file just contains types and documentation for your editor. This
  4. # is NOT executable code, and you won't be able to change the behavior of your
  5. # Seahorse programs by editing this file.
  6. from typing import *
  7. from math import floor, ceil
  8. T = TypeVar('T')
  9. N = TypeVar('N')
  10. # ==========
  11. # Rust types
  12. # ==========
  13. class u8:
  14. """8-bit unsigned integer."""
  15. def __init__(self, _: Any) -> 'u8':
  16. """Construct an u8."""
  17. def __add__(self, other: 'u8') -> 'u8':
  18. pass
  19. def __radd__(self, other: 'u8') -> 'u8':
  20. pass
  21. def __iadd__(self, other: 'u8') -> 'u8':
  22. pass
  23. def __sub__(self, other: 'u8') -> 'u8':
  24. pass
  25. def __rsub__(self, other: 'u8') -> 'u8':
  26. pass
  27. def __isub__(self, other: 'u8') -> 'u8':
  28. pass
  29. def __mul__(self, other: 'u8') -> 'u8':
  30. pass
  31. def __rmul__(self, other: 'u8') -> 'u8':
  32. pass
  33. def __imul__(self, other: 'u8') -> 'u8':
  34. pass
  35. def __truediv__(self, other: 'f64') -> 'f64':
  36. pass
  37. def __rtruediv__(self, other: 'f64') -> 'f64':
  38. pass
  39. def __itruediv__(self, other: 'f64') -> 'f64':
  40. pass
  41. def __floordiv__(self, other: 'u8') -> 'u8':
  42. pass
  43. def __rfloordiv__(self, other: 'u8') -> 'u8':
  44. pass
  45. def __ifloordiv__(self, other: 'u8') -> 'u8':
  46. pass
  47. def __lt__(self, other: 'u8') -> bool:
  48. pass
  49. def __le__(self, other: 'u8') -> bool:
  50. pass
  51. def __eq__(self, other: 'u8') -> bool:
  52. pass
  53. def __ne__(self, other: 'u8') -> bool:
  54. pass
  55. def __ge__(self, other: 'u8') -> bool:
  56. pass
  57. def __gt__(self, other: 'u8') -> bool:
  58. pass
  59. class u16:
  60. """16-bit unsigned integer."""
  61. def __init__(self, _: Any) -> 'u16':
  62. """Construct an u16."""
  63. def __add__(self, other: 'u16') -> 'u16':
  64. pass
  65. def __radd__(self, other: 'u16') -> 'u16':
  66. pass
  67. def __iadd__(self, other: 'u16') -> 'u16':
  68. pass
  69. def __sub__(self, other: 'u16') -> 'u16':
  70. pass
  71. def __rsub__(self, other: 'u16') -> 'u16':
  72. pass
  73. def __isub__(self, other: 'u16') -> 'u16':
  74. pass
  75. def __mul__(self, other: 'u16') -> 'u16':
  76. pass
  77. def __rmul__(self, other: 'u16') -> 'u16':
  78. pass
  79. def __imul__(self, other: 'u16') -> 'u16':
  80. pass
  81. def __truediv__(self, other: 'f64') -> 'f64':
  82. pass
  83. def __rtruediv__(self, other: 'f64') -> 'f64':
  84. pass
  85. def __itruediv__(self, other: 'f64') -> 'f64':
  86. pass
  87. def __floordiv__(self, other: 'u16') -> 'u16':
  88. pass
  89. def __rfloordiv__(self, other: 'u16') -> 'u16':
  90. pass
  91. def __ifloordiv__(self, other: 'u16') -> 'u16':
  92. pass
  93. def __lt__(self, other: 'u16') -> bool:
  94. pass
  95. def __le__(self, other: 'u16') -> bool:
  96. pass
  97. def __eq__(self, other: 'u16') -> bool:
  98. pass
  99. def __ne__(self, other: 'u16') -> bool:
  100. pass
  101. def __ge__(self, other: 'u16') -> bool:
  102. pass
  103. def __gt__(self, other: 'u16') -> bool:
  104. pass
  105. class u32:
  106. """32-bit unsigned integer."""
  107. def __init__(self, _: Any) -> 'u32':
  108. """Construct an u32."""
  109. def __add__(self, other: 'u32') -> 'u32':
  110. pass
  111. def __radd__(self, other: 'u32') -> 'u32':
  112. pass
  113. def __iadd__(self, other: 'u32') -> 'u32':
  114. pass
  115. def __sub__(self, other: 'u32') -> 'u32':
  116. pass
  117. def __rsub__(self, other: 'u32') -> 'u32':
  118. pass
  119. def __isub__(self, other: 'u32') -> 'u32':
  120. pass
  121. def __mul__(self, other: 'u32') -> 'u32':
  122. pass
  123. def __rmul__(self, other: 'u32') -> 'u32':
  124. pass
  125. def __imul__(self, other: 'u32') -> 'u32':
  126. pass
  127. def __truediv__(self, other: 'f64') -> 'f64':
  128. pass
  129. def __rtruediv__(self, other: 'f64') -> 'f64':
  130. pass
  131. def __itruediv__(self, other: 'f64') -> 'f64':
  132. pass
  133. def __floordiv__(self, other: 'u32') -> 'u32':
  134. pass
  135. def __rfloordiv__(self, other: 'u32') -> 'u32':
  136. pass
  137. def __ifloordiv__(self, other: 'u32') -> 'u32':
  138. pass
  139. def __lt__(self, other: 'u32') -> bool:
  140. pass
  141. def __le__(self, other: 'u32') -> bool:
  142. pass
  143. def __eq__(self, other: 'u32') -> bool:
  144. pass
  145. def __ne__(self, other: 'u32') -> bool:
  146. pass
  147. def __ge__(self, other: 'u32') -> bool:
  148. pass
  149. def __gt__(self, other: 'u32') -> bool:
  150. pass
  151. class u64:
  152. """64-bit unsigned integer."""
  153. def __init__(self, _: Any) -> 'u64':
  154. """Construct an u64."""
  155. def __add__(self, other: 'u64') -> 'u64':
  156. pass
  157. def __radd__(self, other: 'u64') -> 'u64':
  158. pass
  159. def __iadd__(self, other: 'u64') -> 'u64':
  160. pass
  161. def __sub__(self, other: 'u64') -> 'u64':
  162. pass
  163. def __rsub__(self, other: 'u64') -> 'u64':
  164. pass
  165. def __isub__(self, other: 'u64') -> 'u64':
  166. pass
  167. def __mul__(self, other: 'u64') -> 'u64':
  168. pass
  169. def __rmul__(self, other: 'u64') -> 'u64':
  170. pass
  171. def __imul__(self, other: 'u64') -> 'u64':
  172. pass
  173. def __truediv__(self, other: 'f64') -> 'f64':
  174. pass
  175. def __rtruediv__(self, other: 'f64') -> 'f64':
  176. pass
  177. def __itruediv__(self, other: 'f64') -> 'f64':
  178. pass
  179. def __floordiv__(self, other: 'u64') -> 'u64':
  180. pass
  181. def __rfloordiv__(self, other: 'u64') -> 'u64':
  182. pass
  183. def __ifloordiv__(self, other: 'u64') -> 'u64':
  184. pass
  185. def __lt__(self, other: 'u64') -> bool:
  186. pass
  187. def __le__(self, other: 'u64') -> bool:
  188. pass
  189. def __eq__(self, other: 'u64') -> bool:
  190. pass
  191. def __ne__(self, other: 'u64') -> bool:
  192. pass
  193. def __ge__(self, other: 'u64') -> bool:
  194. pass
  195. def __gt__(self, other: 'u64') -> bool:
  196. pass
  197. class u128:
  198. """128-bit unsigned integer."""
  199. def __init__(self, _: Any) -> 'u128':
  200. """Construct an u128."""
  201. def __add__(self, other: 'u128') -> 'u128':
  202. pass
  203. def __radd__(self, other: 'u128') -> 'u128':
  204. pass
  205. def __iadd__(self, other: 'u128') -> 'u128':
  206. pass
  207. def __sub__(self, other: 'u128') -> 'u128':
  208. pass
  209. def __rsub__(self, other: 'u128') -> 'u128':
  210. pass
  211. def __isub__(self, other: 'u128') -> 'u128':
  212. pass
  213. def __mul__(self, other: 'u128') -> 'u128':
  214. pass
  215. def __rmul__(self, other: 'u128') -> 'u128':
  216. pass
  217. def __imul__(self, other: 'u128') -> 'u128':
  218. pass
  219. def __truediv__(self, other: 'f64') -> 'f64':
  220. pass
  221. def __rtruediv__(self, other: 'f64') -> 'f64':
  222. pass
  223. def __itruediv__(self, other: 'f64') -> 'f64':
  224. pass
  225. def __floordiv__(self, other: 'u128') -> 'u128':
  226. pass
  227. def __rfloordiv__(self, other: 'u128') -> 'u128':
  228. pass
  229. def __ifloordiv__(self, other: 'u128') -> 'u128':
  230. pass
  231. def __lt__(self, other: 'u128') -> bool:
  232. pass
  233. def __le__(self, other: 'u128') -> bool:
  234. pass
  235. def __eq__(self, other: 'u128') -> bool:
  236. pass
  237. def __ne__(self, other: 'u128') -> bool:
  238. pass
  239. def __ge__(self, other: 'u128') -> bool:
  240. pass
  241. def __gt__(self, other: 'u128') -> bool:
  242. pass
  243. class i8:
  244. """8-bit signed integer."""
  245. def __init__(self, _: Any) -> 'i8':
  246. """Construct an i8."""
  247. def __add__(self, other: 'i8') -> 'i8':
  248. pass
  249. def __radd__(self, other: 'i8') -> 'i8':
  250. pass
  251. def __iadd__(self, other: 'i8') -> 'i8':
  252. pass
  253. def __sub__(self, other: 'i8') -> 'i8':
  254. pass
  255. def __rsub__(self, other: 'i8') -> 'i8':
  256. pass
  257. def __isub__(self, other: 'i8') -> 'i8':
  258. pass
  259. def __mul__(self, other: 'i8') -> 'i8':
  260. pass
  261. def __rmul__(self, other: 'i8') -> 'i8':
  262. pass
  263. def __imul__(self, other: 'i8') -> 'i8':
  264. pass
  265. def __truediv__(self, other: 'f64') -> 'f64':
  266. pass
  267. def __rtruediv__(self, other: 'f64') -> 'f64':
  268. pass
  269. def __itruediv__(self, other: 'f64') -> 'f64':
  270. pass
  271. def __floordiv__(self, other: 'i8') -> 'i8':
  272. pass
  273. def __rfloordiv__(self, other: 'i8') -> 'i8':
  274. pass
  275. def __ifloordiv__(self, other: 'i8') -> 'i8':
  276. pass
  277. class i16:
  278. """16-bit signed integer."""
  279. def __init__(self, _: Any) -> 'i16':
  280. """Construct an i16."""
  281. def __add__(self, other: 'i16') -> 'i16':
  282. pass
  283. def __radd__(self, other: 'i16') -> 'i16':
  284. pass
  285. def __iadd__(self, other: 'i16') -> 'i16':
  286. pass
  287. def __sub__(self, other: 'i16') -> 'i16':
  288. pass
  289. def __rsub__(self, other: 'i16') -> 'i16':
  290. pass
  291. def __isub__(self, other: 'i16') -> 'i16':
  292. pass
  293. def __mul__(self, other: 'i16') -> 'i16':
  294. pass
  295. def __rmul__(self, other: 'i16') -> 'i16':
  296. pass
  297. def __imul__(self, other: 'i16') -> 'i16':
  298. pass
  299. def __truediv__(self, other: 'f64') -> 'f64':
  300. pass
  301. def __rtruediv__(self, other: 'f64') -> 'f64':
  302. pass
  303. def __itruediv__(self, other: 'f64') -> 'f64':
  304. pass
  305. def __floordiv__(self, other: 'i16') -> 'i16':
  306. pass
  307. def __rfloordiv__(self, other: 'i16') -> 'i16':
  308. pass
  309. def __ifloordiv__(self, other: 'i16') -> 'i16':
  310. pass
  311. def __lt__(self, other: 'i16') -> bool:
  312. pass
  313. def __le__(self, other: 'i16') -> bool:
  314. pass
  315. def __eq__(self, other: 'i16') -> bool:
  316. pass
  317. def __ne__(self, other: 'i16') -> bool:
  318. pass
  319. def __ge__(self, other: 'i16') -> bool:
  320. pass
  321. def __gt__(self, other: 'i16') -> bool:
  322. pass
  323. class i32:
  324. """32-bit signed integer."""
  325. def __init__(self, _: Any) -> 'i32':
  326. """Construct an i32."""
  327. def __add__(self, other: 'i32') -> 'i32':
  328. pass
  329. def __radd__(self, other: 'i32') -> 'i32':
  330. pass
  331. def __iadd__(self, other: 'i32') -> 'i32':
  332. pass
  333. def __sub__(self, other: 'i32') -> 'i32':
  334. pass
  335. def __rsub__(self, other: 'i32') -> 'i32':
  336. pass
  337. def __isub__(self, other: 'i32') -> 'i32':
  338. pass
  339. def __mul__(self, other: 'i32') -> 'i32':
  340. pass
  341. def __rmul__(self, other: 'i32') -> 'i32':
  342. pass
  343. def __imul__(self, other: 'i32') -> 'i32':
  344. pass
  345. def __truediv__(self, other: 'f64') -> 'f64':
  346. pass
  347. def __rtruediv__(self, other: 'f64') -> 'f64':
  348. pass
  349. def __itruediv__(self, other: 'f64') -> 'f64':
  350. pass
  351. def __floordiv__(self, other: 'i32') -> 'i32':
  352. pass
  353. def __rfloordiv__(self, other: 'i32') -> 'i32':
  354. pass
  355. def __ifloordiv__(self, other: 'i32') -> 'i32':
  356. pass
  357. def __lt__(self, other: 'i32') -> bool:
  358. pass
  359. def __le__(self, other: 'i32') -> bool:
  360. pass
  361. def __eq__(self, other: 'i32') -> bool:
  362. pass
  363. def __ne__(self, other: 'i32') -> bool:
  364. pass
  365. def __ge__(self, other: 'i32') -> bool:
  366. pass
  367. def __gt__(self, other: 'i32') -> bool:
  368. pass
  369. class i64:
  370. """64-bit signed integer."""
  371. def __init__(self, _: Any) -> 'i64':
  372. """Construct an i64."""
  373. def __add__(self, other: 'i64') -> 'i64':
  374. pass
  375. def __radd__(self, other: 'i64') -> 'i64':
  376. pass
  377. def __iadd__(self, other: 'i64') -> 'i64':
  378. pass
  379. def __sub__(self, other: 'i64') -> 'i64':
  380. pass
  381. def __rsub__(self, other: 'i64') -> 'i64':
  382. pass
  383. def __isub__(self, other: 'i64') -> 'i64':
  384. pass
  385. def __mul__(self, other: 'i64') -> 'i64':
  386. pass
  387. def __rmul__(self, other: 'i64') -> 'i64':
  388. pass
  389. def __imul__(self, other: 'i64') -> 'i64':
  390. pass
  391. def __truediv__(self, other: 'f64') -> 'f64':
  392. pass
  393. def __rtruediv__(self, other: 'f64') -> 'f64':
  394. pass
  395. def __itruediv__(self, other: 'f64') -> 'f64':
  396. pass
  397. def __floordiv__(self, other: 'i64') -> 'i64':
  398. pass
  399. def __rfloordiv__(self, other: 'i64') -> 'i64':
  400. pass
  401. def __ifloordiv__(self, other: 'i64') -> 'i64':
  402. pass
  403. def __lt__(self, other: 'i64') -> bool:
  404. pass
  405. def __le__(self, other: 'i64') -> bool:
  406. pass
  407. def __eq__(self, other: 'i64') -> bool:
  408. pass
  409. def __ne__(self, other: 'i64') -> bool:
  410. pass
  411. def __ge__(self, other: 'i64') -> bool:
  412. pass
  413. def __gt__(self, other: 'i64') -> bool:
  414. pass
  415. class i128:
  416. """128-bit signed integer."""
  417. def __init__(self, _: Any) -> 'i128':
  418. """Construct an i128."""
  419. def __add__(self, other: 'i128') -> 'i128':
  420. pass
  421. def __radd__(self, other: 'i128') -> 'i128':
  422. pass
  423. def __iadd__(self, other: 'i128') -> 'i128':
  424. pass
  425. def __sub__(self, other: 'i128') -> 'i128':
  426. pass
  427. def __rsub__(self, other: 'i128') -> 'i128':
  428. pass
  429. def __isub__(self, other: 'i128') -> 'i128':
  430. pass
  431. def __mul__(self, other: 'i128') -> 'i128':
  432. pass
  433. def __rmul__(self, other: 'i128') -> 'i128':
  434. pass
  435. def __imul__(self, other: 'i128') -> 'i128':
  436. pass
  437. def __truediv__(self, other: 'f64') -> 'f64':
  438. pass
  439. def __rtruediv__(self, other: 'f64') -> 'f64':
  440. pass
  441. def __itruediv__(self, other: 'f64') -> 'f64':
  442. pass
  443. def __floordiv__(self, other: 'i128') -> 'i128':
  444. pass
  445. def __rfloordiv__(self, other: 'i128') -> 'i128':
  446. pass
  447. def __ifloordiv__(self, other: 'i128') -> 'i128':
  448. pass
  449. def __lt__(self, other: 'i128') -> bool:
  450. pass
  451. def __le__(self, other: 'i128') -> bool:
  452. pass
  453. def __eq__(self, other: 'i128') -> bool:
  454. pass
  455. def __ne__(self, other: 'i128') -> bool:
  456. pass
  457. def __ge__(self, other: 'i128') -> bool:
  458. pass
  459. def __gt__(self, other: 'i128') -> bool:
  460. pass
  461. class f64:
  462. """64-bit floating point number."""
  463. def __init__(self, _: Any) -> 'f64':
  464. """Construct an f64."""
  465. def __add__(self, other: 'f64') -> 'f64':
  466. pass
  467. def __radd__(self, other: 'f64') -> 'f64':
  468. pass
  469. def __iadd__(self, other: 'f64') -> 'f64':
  470. pass
  471. def __sub__(self, other: 'f64') -> 'f64':
  472. pass
  473. def __rsub__(self, other: 'f64') -> 'f64':
  474. pass
  475. def __isub__(self, other: 'f64') -> 'f64':
  476. pass
  477. def __mul__(self, other: 'f64') -> 'f64':
  478. pass
  479. def __rmul__(self, other: 'f64') -> 'f64':
  480. pass
  481. def __imul__(self, other: 'f64') -> 'f64':
  482. pass
  483. def __truediv__(self, other: 'f64') -> 'f64':
  484. pass
  485. def __rtruediv__(self, other: 'f64') -> 'f64':
  486. pass
  487. def __itruediv__(self, other: 'f64') -> 'f64':
  488. pass
  489. def __floordiv__(self, other: 'f64') -> 'f64':
  490. pass
  491. def __rfloordiv__(self, other: 'f64') -> 'f64':
  492. pass
  493. def __ifloordiv__(self, other: 'f64') -> 'f64':
  494. pass
  495. def __lt__(self, other: 'f64') -> bool:
  496. pass
  497. def __le__(self, other: 'f64') -> bool:
  498. pass
  499. def __eq__(self, other: 'f64') -> bool:
  500. pass
  501. def __ne__(self, other: 'f64') -> bool:
  502. pass
  503. def __ge__(self, other: 'f64') -> bool:
  504. pass
  505. def __gt__(self, other: 'f64') -> bool:
  506. pass
  507. class Array(Generic[T, N]):
  508. """
  509. A fixed-length array: contains type T and has size N.
  510. N must be known at compile-time, and may not be anything other than a non-negative integer literal. Example:
  511. ```
  512. # Good
  513. a: Array[u8, 4]
  514. # Bad
  515. N = 4
  516. a: Array[u8, N]
  517. ```
  518. """
  519. def __init__(iterable: Iterable[T], len: N) -> 'Array[T, N]':
  520. """
  521. Construct an array from an iterable and a length.
  522. The parameter len must be known at compile-time, and may not be anything other than a non-negative integer literal. Example:
  523. ```
  524. a = [0, 1, 2, 3]
  525. # Good
  526. Array(a, 4)
  527. # Compiles, but will definitely error at runtime
  528. Array(a, 5)
  529. # Bad (will not compile)
  530. a = [0, 1, 2, 3]
  531. Array(a, len(a))
  532. ```
  533. """
  534. def __getitem__(self, index: Any) -> T:
  535. """
  536. Index into this array.
  537. Like Python's native list type, performs wrapping indexing - if you pass in -1, you'll get the last element of the array.
  538. """
  539. def array(*elements: T) -> Array[T, N]:
  540. """
  541. Create an array from a variadic list of elements. Example:
  542. ```
  543. # Array[u64, 3]
  544. array(u64(0), 1, 2)
  545. # Array[str, 4]
  546. array('seahorse', 'is', 'the', 'best!')
  547. ```
  548. """
  549. class Enum:
  550. """
  551. A type that can have one of multiple named values.
  552. Note that unlike Rust enums, these cannot contain any data (other than the variant itself). Example:
  553. ```
  554. class MyEnum(Enum):
  555. ONE = 1
  556. TWO = 2
  557. THREE = 3
  558. @instruction
  559. def use_enum(code: MyEnum):
  560. if code == MyEnum.ONE:
  561. print(1)
  562. # ...
  563. ```
  564. """
  565. # ============
  566. # Solana types
  567. # ============
  568. class Pubkey:
  569. """32-byte account identifier."""
  570. def find_program_address(seeds: List[Any], program_id: 'Pubkey' = None) -> Tuple['Pubkey', u8]:
  571. """
  572. 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).
  573. @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.
  574. @param program_id: The pubkey of the program that the PDA belongs to. Defaults to the current program's key.
  575. @returns: The canonical pubkey and bump seed.
  576. """
  577. class AccountWithKey:
  578. """Generic Solana account."""
  579. def key(self) -> Pubkey:
  580. """Get this account's key."""
  581. class Account(AccountWithKey):
  582. """User-defined Solana account."""
  583. def transfer_lamports(self, to: AccountWithKey, amount: u64):
  584. """
  585. Transfer some SOL directly to another account. Since this account is program-owned, this transfer does not require a CPI.
  586. @param to: The recipient Solana account.
  587. @param amount: The amount (in lamports, not SOL) to transfer.
  588. """
  589. class Event:
  590. """Anchor event that clients can listen for"""
  591. def emit(self):
  592. """
  593. Emit the event to the blockchain
  594. """
  595. class Signer(AccountWithKey):
  596. """Instruction signer."""
  597. def transfer_lamports(self, to: AccountWithKey, amount: u64):
  598. """
  599. Transfer some SOL directly to another account. Unlike using transfer_lamports from a program account, this transfer will require a CPI.
  600. @param to: The recipient Solana account.
  601. @param amount: The amount (in lamports, not SOL) to transfer.
  602. """
  603. class Empty(Generic[T]):
  604. """An account that needs to be initialized."""
  605. 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:
  606. """
  607. Initialize the account.
  608. @param payer: The account that will pay for the rent cost of the initialized account. Must be an instruction signer.
  609. @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.
  610. @param mint: If initializing a TokenAccount, this is the mint that the account belongs to.
  611. @param decimals: If initializing a TokenMint, this is the number of decimals the new token has.
  612. @param authority: If initializing a TokenAccount/TokenMint, this is the account that has authority over the account.
  613. @param associated: If initializing an associated token account, must be set to true.
  614. @param space: If initializing a program account, you can use this to overwrite Seahorse's calculation of the account size.
  615. @param padding: If initializing a program account, you can use this to add extra space to Seahorse's calculation of the account size.
  616. @returns: The new, initialized account. All of the data in this account will be set to 0, bytewise.
  617. """
  618. def bump(self) -> u8:
  619. """
  620. Get this account's bump, needed if you want to use this account to sign CPI calls.
  621. 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.
  622. """
  623. def key(self) -> Pubkey:
  624. """Get this account's key."""
  625. class CpiAccount:
  626. """Account and metadata used for making arbitrary CPIs (via `Program.invoke`)."""
  627. def __init__(account: AccountWithKey, mut: bool = False, signer: bool = False, seeds: List[Any] = None) -> 'CpiAccount':
  628. """
  629. Create the CpiAccount.
  630. @param account: The account being passed to the CPI.
  631. @param mut: Whether this account needs to be mutable for the CPI - defaults to false.
  632. @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.
  633. @param seeds: PDA signer seeds, if this account needs to sign the CPI. Mutually exclusive with signer.
  634. """
  635. class Program(AccountWithKey):
  636. """Arbitrary program."""
  637. def invoke(self, accounts: List[CpiAccount], data: List[u8]):
  638. """
  639. 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.
  640. @param accounts: List of accounts being passed to the CPI - the program itself does not need to be in here.
  641. @param data: "Raw" list of bytes used to tell the program what to do, pass args, etc.
  642. """
  643. class UncheckedAccount(AccountWithKey):
  644. """
  645. Raw account that has had no safety checks performed on it.
  646. 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.
  647. """
  648. class Clock:
  649. """
  650. Solana's Clock sysvar.
  651. Consult Solana's reference to learn more. Information copied from https://docs.rs/solana-program/1.14.3/solana_program/clock/struct.Clock.html.
  652. """
  653. def slot(self) -> u64:
  654. """Get the current network/bank Slot."""
  655. def epoch_start_timestamp(self) -> i64:
  656. """Get the timestamp of the first Slot in this Epoch."""
  657. def epoch(self) -> u64:
  658. """Get the bank Epoch."""
  659. def leader_schedule_epoch(self) -> u64:
  660. """Get the future Epoch for which the leader schedule has most recently been calculated."""
  661. def unix_timestamp(self) -> i64:
  662. """
  663. Get the estimated current UNIX timestamp.
  664. 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.
  665. """
  666. class TokenAccount(AccountWithKey):
  667. """SPL token account."""
  668. def authority(self) -> Pubkey:
  669. """Get the owner of this token account."""
  670. def amount(self) -> u64:
  671. """Get the amount of token stored in this account."""
  672. def mint(self) -> Pubkey:
  673. """Get the mint that this token account corresponds to."""
  674. def transfer(self, authority: AccountWithKey, to: 'TokenAccount', amount: u64, signer: List[Any] = None):
  675. """
  676. Transfer funds from this SPL token account to another.
  677. @param authority: The account that owns this TokenAccount. Must be an instruction signer or the account given by the `signer` param.
  678. @param to: The recipient TokenAccount.
  679. @param amount: How much (in *native* token units) to transfer.
  680. @param signer: (Optional) seeds for the signature of a PDA.
  681. """
  682. class TokenMint(AccountWithKey):
  683. """SPL token mint."""
  684. def authority(self) -> Pubkey:
  685. """Get the owner of this token mint."""
  686. def freeze_authority(self) -> Pubkey:
  687. """Get the freeze authority of this token mint."""
  688. def decimals(self) -> u8:
  689. """Get the number of decimals for this token."""
  690. def supply(self) -> u64:
  691. """Get the amount of this token that exists."""
  692. def mint(self, authority: AccountWithKey, to: TokenAccount, amount: u64, signer: List[Any] = None):
  693. """
  694. Mint new tokens to a token account.
  695. @param authority: The account that owns this TokenMint. Must be an instruction signer or the account given by the `signer` param.
  696. @param to: The recipient TokenAccount.
  697. @param amount: How much (in *native* token units) to mint.
  698. @param signer: (Optional) seeds for the signature of a PDA.
  699. """
  700. def burn(self, authority: AccountWithKey, holder: TokenAccount, amount: u64, signer: List[Any] = None):
  701. """
  702. Burn tokens from a token account.
  703. @param authority: The account that owns the `holder` TokenAccount. Must be an instruction signer or the account given by the `signer` param.
  704. @param holder: The TokenAccount to burn from.
  705. @param amount: How much (in *native* token units) to burn.
  706. @param signer: (Optional) seeds for the signature of a PDA.
  707. """
  708. # ================
  709. # Helper functions
  710. # ================
  711. def declare_id(id: str):
  712. """Inform Anchor what this program's ID is.
  713. @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.
  714. """
  715. def instruction(function: Callable[..., None]) -> Callable[..., None]:
  716. """Decorator to turn a function into a program instruction."""
  717. def dataclass(function: Callable[..., None]) -> Callable[..., None]:
  718. """Decorator to create an automatic default class constructor."""
  719. def int_bytes(n: Any, be: bool = False) -> List[u8]:
  720. """
  721. Convenience method to turn an integer type into a little-endian (by default) list of bytes.
  722. @param n: The integer you wish to convert to bytes.
  723. @param be: Whether you want the conversion to be big-endian - defaults to false.
  724. """
  725. def size(ob: str) -> u64:
  726. """
  727. Get the size of an object in bytes.
  728. Currently this is only supported for strings.
  729. @param ob: The object to get the size of.
  730. """