{"id":13409879,"url":"https://github.com/auditless/suna","last_synced_at":"2025-03-14T15:30:56.511Z","repository":{"id":160837101,"uuid":"611733702","full_name":"auditless/suna","owner":"auditless","description":"Typesafe opinionated abstractions for developing Cairo 1.0 smart contracts","archived":false,"fork":false,"pushed_at":"2023-06-12T10:08:15.000Z","size":2443,"stargazers_count":19,"open_issues_count":4,"forks_count":3,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-07-31T20:39:23.157Z","etag":null,"topics":["cairo","library","starknet"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/auditless.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-03-09T12:42:18.000Z","updated_at":"2024-05-06T09:12:19.000Z","dependencies_parsed_at":null,"dependency_job_id":"eddfa801-4aad-4e74-85f1-8aade8044f73","html_url":"https://github.com/auditless/suna","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":"auditless/cairo-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/auditless%2Fsuna","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/auditless%2Fsuna/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/auditless%2Fsuna/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/auditless%2Fsuna/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/auditless","download_url":"https://codeload.github.com/auditless/suna/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243600539,"owners_count":20317292,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cairo","library","starknet"],"created_at":"2024-07-30T20:01:03.852Z","updated_at":"2025-03-14T15:30:56.495Z","avatar_url":"https://github.com/auditless.png","language":"Rust","funding_links":[],"categories":["Libraries"],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003cimg src=\".github/cover.png\" alt=\"Suna Cover Photo\" width=\"400\"\u003e\n\u003c/p\u003e\n\n# Suna ![PRs Welcome](https://img.shields.io/badge/PRs-welcome-green.svg) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/auditless/suna/blob/main/LICENSE) \u003ca href=\"https://github.com/auditless/suna/actions/workflows/test.yaml\"\u003e \u003cimg src=\"https://github.com/auditless/suna/actions/workflows/test.yaml/badge.svg?event=push\" alt=\"CI Badge\"/\u003e \u003c/a\u003e\n\n[Built with **`auditless/cairo-template`**](https://github.com/auditless/cairo-template)\n\nTypesafe opinionated abstractions for developing Cairo 1.0 smart contracts.\nOriginally created to facilitate [Yagi Finance](https://www.yagi.fi) smart contract development.\n\n## What is included\n\n- [`suna.math.u256`](https://github.com/auditless/suna/blob/main/src/math/u256.cairo): A `Zeroable` trait implementation for `u256`\n- [`suna.math.u60f18`](https://github.com/auditless/suna/blob/main/src/math/u60f18.cairo): An unsigned fixed point decimal type based on `u256`; `MulDiv` trait and operators\n\n## Warning\n\nSuna is an experimental and unaudited library and is subject to a lot of iteration.\nThere may be bugs.\n\n\n## How to use the library\n\nYou can directly add Suna to your Scarb dependencies:\n\n```toml\n[dependencies]\nsuna = { git = \"https://github.com/auditless/suna.git\" }\n```\n\nThe below examples are illustrative and you can find more\nfunctions by reading the code and tests directly.\n\n## `Zeroable` trait implementation for `u256`\n\nMost DeFi applications will use the `u256` type to deal with token amounts. Unfortunately the trait implementations are not yet complete.\nThis is how you can use the Zeroable implementation:\n\n```cairo\nuse suna::math::u256::U256Zeroable;\n\nlet number: u256 = 33_u256;\n// Check if number is zero\nZeroable::is_zero(0)\n```\n\n### `MulDiv` trait\n\nWhen building a yield/pooling application, you may need a way to\ncalculate how much of an underlying asset a given share owner\ncontrols. You can do it as follows:\n\n```cairo\nuse suna::math::u60f18::U256MulDiv;\n\nlet total_supply: u256 = 10000_u256;\nlet shares: u256 = 33_u256;\nlet total_assets: u256 = 853000000000000000000_u256;\n// Calculates shares * total_assets / total_supply safely\nlet assets_owned = U256MulDiv::mul_div(shares, total_assets, total_supply);\n```\n\n### An 18-decimal fixed point type `U60F18`\n\nYou may also want to maintain certain fractional values such as weights\nor interest rates in your application using 18 decimals. To do that,\nyou can use our `U60F18` type which supports conversion from `u256`\nand many of the standard operators:\n\n```cairo\nuse traits::Into;\nuse suna::math::u60f18::U256ToU60F18;\nuse suna::math::u60f18::U60F18DivEq;\n\n// Represent an interest rate of 2%\nlet mut interest_rate: U60F18 = 2.into();\ninterest_rate /= 100.into();\n```\n\n## Design principles\n\n- Be useful to developers building production Cairo contracts\n- Design from first principles with both Rust and smart contract idioms in mind\n- Build typesafe and efficient abstractions that are consistently designed\n- Respect and embrace the `corelib` trait hierarchy\n- Aspire to build well-documented and declarative code\n\n## How to contribute\n\n- Read the Cairo 1.0 setup guide at https://github.com/auditless/cairo-template\n- Check our issues for scoped tasks or propose/request a new one by opening an issue\n- Submit a PR linking the relevant issue\n- You may also submit a PR that fixes a bug or nit directly\n\n## Thanks to\n\n- The [Quaireaux](https://github.com/keep-starknet-strange/quaireaux) team for paving the way for Cairo 1.0 library development\n- The [Scarb](https://github.com/software-mansion/scarb) contributors for creating a pioneering package manager which we rely on\n- The [OpenZeppelin](https://github.com/OpenZeppelin/openzeppelin-contracts) team for the mulDiv interface\n- S. Tsuchiya for the cover photo\n- Last but not least, the StarkWare team for building the first smart contract language that is a joy to use\n\n## License\n\n[MIT](https://github.com/auditless/suna/blob/main/LICENSE) © [Auditless Limited](https://www.auditless.com)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fauditless%2Fsuna","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fauditless%2Fsuna","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fauditless%2Fsuna/lists"}